官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 甘洛县| 武威市| 井冈山市| 赤水市| 阿拉尔市| 正蓝旗| 三明市| 洪湖市| 连江县| 大田县| 健康| 千阳县| 凌云县| 吉安县| 湖北省| 桐柏县| 阿拉善右旗| 西平县| 瑞昌市| 葵青区| 宁夏| 白玉县| 防城港市| 威远县| 和林格尔县| 建始县| 鄢陵县| 铅山县| 石棉县| 郴州市| 抚远县| 珲春市| 崇明县| 平乡县| 仁寿县| 鄱阳县| 格尔木市| 酒泉市| 乌拉特后旗| 嘉荫县| 威远县|