Run as Spring Boot

The preceding example can be easily converted to a Spring Boot application by following the ensuing additional steps. This process won't cover many of the trivial steps that we have done previously. You need to have one more configuration file, SpringSecurityConfig.java, the details of which are as follows.

You can create a new file, usually named Run.java, with the following code:

@SpringBootApplication
public class Run {
public static void main(String[] args) {
SpringApplication.run(Run.class, args);
}
}

It's a very simple file with an important annotation in it, @SpringBootApplication. We took away the Spring MVC configuration class and put the following properties in the application.properties file. This is just another way to avoid creating a new Spring MVC configuration file and instead use the properties file:

spring.mvc.view.prefix: /WEB-INF/views/
spring.mvc.view.suffix: .jsp

As earlier, everything else is kept intact. For the full project, refer to the book's GitHub page in the spring-boot-in-memory-basic-authentication project.

Open a command prompt and enter the following command:

mvn spring-boot:run

Open the browser and navigate to http://localhost:8080, and you should be provided with a basic authentication dialog. After successful login, you should be taken to the user home page, as shown earlier.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.239.139