Spring Boot 3.0.0 Tutorial - CORS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome in this video we are going to discuss spring boot cross origin resource sharing or course and the different possibilities of configuration in Spring boot 3. [Music] if you want more info on Cross origin resource sharing serve to the developer Mozilla website on this website you will find everything about cross-origin resource sharing back in the clips we can show a first example of cross-origin resource sharing we have started a new project that we will briefly go over in the maven Palm XML file we are using the latest version of spring boot 3.0.5 furthermore we have spring boot starter web and spring boots started time leaf in the application properties file we have server port 8080. furthermore we have two controller classes home controller and course controller in the home controller we have The annotation controller and one method home which Returns the index HTML file the course controller is a rest controller and the method pours this returns a string boot course the last file is the index HTML file here we have a short JavaScript function here we use the fetch IPA to fetch the text from the core's endpoint convert it to text and make it visible in the HTML pay special attention to http localhost 8080 course we can now start the project and see in a browser what happens we can now view the result in a browser first we open localhost 8080 we get the expected result the title spring boot tutorial and the text spring boot course if we open 127.0.0.180 we get a different result The Tech Spring boot course is not showing and in the console we get a course policy error message this is because localhost and 127.0.0.1 open the same page but are a different domain we will now open a second example with an external controller we're back in eclipse for a second example we started a second project with the following classes the maven Palm XML file uses the latest version of spring boot 3.0.5 again and further the spring boot starter web dependency in the application properties file we have server port 9000. and finally the rest controller course controller with one method course this returns spring boot course from each TTP localhost 9000. in the first project we modified the index HTML file a bit in the JavaScript function we have a second fetch that loads the endpoint localhost 9000. converts it to text and let it seen on the screen we have started both the projects and are now watching the results if we open localhost 8080 we get only the first text for the second text we get a course error this time because the ports are not the same if we open 127.0.0.180 we get neither of the two texts and we get back the error from the first example we can now go to Eclipse to modify the configuration so that everything works fine we are now back in Eclipse to propose a solution the first class is the course config class in the first project we have the configuration annotation and the bean annotation above the webmvc configure method this overrides the ad cores mappings method this is where we can configure everything in this example we keep it simple and only have that ad mapping course allowed Origins 127.0.0.180. and allowed methods get in the course config class in the second project we have roughly the same configuration ad mapping course allowed Origins 127.0.0.180 and localhost 8080. and allowed methods get we can now start both projects and look at the results in our browser in a browser we first open localhost 8080. this time we see the text of both endpoints then we open 127.0.0.1880. again we see both texts of the endpoints this is the end of this video in the next video we will extend the cross-origin resource sharing configuration with Spring Security thanks for following and don't forget to subscribe and like this video
Info
Channel: Spring Boot TUTORIAL.
Views: 1,788
Rating: undefined out of 5
Keywords: Spring, Spring Boot, spring Boot 3.0.0, Spring Security, Security, SecurityFilterChain, Bean, Github, Ecloipse, Spring Data JPA, Mariadb, DataBase, JWT, Json Web Token, WebSecurityConfigurerAdapter, Deprecated, authorizeRequests, Web, Web Client, Http, Http interface, Jdbc, Spring Data JDBC, one-to-one, one-to-many, relation, Many-to-many, OAuth2, Spring authorization server, Spring Resource Server, Spring Oauth2 Client, Cross-Origin Resource Sharing, CORS
Id: B0_84Hiy4A8
Channel Id: undefined
Length: 5min 53sec (353 seconds)
Published: Mon Apr 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.