新建一个maven工程,名为spring-security,pom文件如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.5.RELEASE</version> </parent> <groupId>net.maxwoods.spring</groupId> <artifactId>spring-security</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> </dependencies> </project>
创建启动类:
package net.maxwoods.spring; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SpringSecurity { public static void main(String[] args) { SpringApplication.run(SpringSecurity.class,args); } }
创建控制器类:
package net.maxwoods.spring.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class IndexController { @RequestMapping("/") public String index() { return "index.html"; } }
在resources目录下创建templates目录,创建index.html,内容如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Spring Security</title> <style> html,body { background-color: aquamarine; height: 100%; margin: 0 0 0 0; } #logo { background-color: brown; height: 100%; font-size: 72px; color: burlywood; display: flex; justify-content:center; align-items:Center; } </style> </head> <body> <div id="logo">Spring Security</div> </body> </html>
运行该项目,浏览器打开http://localhost:8080,看到如下界面,说明Spring Security启用成功!
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END