创建项目
创建一个普通的SpringBoot项目
- parent.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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.songleibing.demo</groupId>
<artifactId>spring-security-demo</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<modules>
<module>spring-security-demo-01</module>
</modules>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.3.7.RELEASE</spring-boot.version>
</properties>
<dependencies>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
- pom.xml
<?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>
<artifactId>spring-security-demo-01</artifactId>
<parent>
<groupId>com.songleibing.demo</groupId>
<artifactId>spring-security-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.7.RELEASE</version>
<configuration>
<mainClass>com.songleibing.demo.spring.security.SpringSecurityDemoApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
- 启动项目
/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/bin/java -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=52629:/Applications/IntelliJ IDEA.app/Contents/bin -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath /Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/charsets.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/ext/cldrdata.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/ext/dnsns.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/ext/jaccess.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/ext/localedata.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/ext/nashorn.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/ext/sunec.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/ext/zipfs.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/jce.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/jfr.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/jsse.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/management-agent.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/resources.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/jre/lib/rt.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/lib/dt.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/lib/jconsole.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/lib/sa-jdi.jar:/Users/garen/Library/Java/JavaVirtualMachines/temurin-1.8.0_312/Contents/Home/lib/tools.jar:/Users/garen/Documents/workspace/spring-security-demo/spring-security-demo-01/target/classes:/Users/garen/.m2/repository/org/springframework/boot/spring-boot-starter-security/2.3.7.RELEASE/spring-boot-starter-security-2.3.7.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/boot/spring-boot-starter/2.3.7.RELEASE/spring-boot-starter-2.3.7.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/boot/spring-boot/2.3.7.RELEASE/spring-boot-2.3.7.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.3.7.RELEASE/spring-boot-autoconfigure-2.3.7.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.3.7.RELEASE/spring-boot-starter-logging-2.3.7.RELEASE.jar:/Users/garen/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar:/Users/garen/.m2/repository/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar:/Users/garen/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.13.3/log4j-to-slf4j-2.13.3.jar:/Users/garen/.m2/repository/org/apache/logging/log4j/log4j-api/2.13.3/log4j-api-2.13.3.jar:/Users/garen/.m2/repository/org/slf4j/jul-to-slf4j/1.7.30/jul-to-slf4j-1.7.30.jar:/Users/garen/.m2/repository/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/Users/garen/.m2/repository/org/yaml/snakeyaml/1.26/snakeyaml-1.26.jar:/Users/garen/.m2/repository/org/springframework/spring-aop/5.2.12.RELEASE/spring-aop-5.2.12.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/spring-beans/5.2.12.RELEASE/spring-beans-5.2.12.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/security/spring-security-config/5.3.6.RELEASE/spring-security-config-5.3.6.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/spring-context/5.2.12.RELEASE/spring-context-5.2.12.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/security/spring-security-web/5.3.6.RELEASE/spring-security-web-5.3.6.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/spring-expression/5.2.12.RELEASE/spring-expression-5.2.12.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/boot/spring-boot-starter-web/2.3.7.RELEASE/spring-boot-starter-web-2.3.7.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/boot/spring-boot-starter-json/2.3.7.RELEASE/spring-boot-starter-json-2.3.7.RELEASE.jar:/Users/garen/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.11.3/jackson-databind-2.11.3.jar:/Users/garen/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.11.3/jackson-annotations-2.11.3.jar:/Users/garen/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.11.3/jackson-core-2.11.3.jar:/Users/garen/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.11.3/jackson-datatype-jdk8-2.11.3.jar:/Users/garen/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.11.3/jackson-datatype-jsr310-2.11.3.jar:/Users/garen/.m2/repository/com/fasterxml/jackson/module/jackson-module-parameter-names/2.11.3/jackson-module-parameter-names-2.11.3.jar:/Users/garen/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/2.3.7.RELEASE/spring-boot-starter-tomcat-2.3.7.RELEASE.jar:/Users/garen/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.41/tomcat-embed-core-9.0.41.jar:/Users/garen/.m2/repository/org/glassfish/jakarta.el/3.0.3/jakarta.el-3.0.3.jar:/Users/garen/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/9.0.41/tomcat-embed-websocket-9.0.41.jar:/Users/garen/.m2/repository/org/springframework/spring-web/5.2.12.RELEASE/spring-web-5.2.12.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/spring-webmvc/5.2.12.RELEASE/spring-webmvc-5.2.12.RELEASE.jar:/Users/garen/.m2/repository/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar:/Users/garen/.m2/repository/org/springframework/spring-core/5.2.12.RELEASE/spring-core-5.2.12.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/spring-jcl/5.2.12.RELEASE/spring-jcl-5.2.12.RELEASE.jar:/Users/garen/.m2/repository/org/springframework/security/spring-security-core/5.3.6.RELEASE/spring-security-core-5.3.6.RELEASE.jar com.songleibing.demo.spring.security.SpringSecurityDemo01
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.7.RELEASE)
2022-09-28 23:02:34.532 INFO 3312 --- [ main] c.s.d.s.security.SpringSecurityDemo01 : Starting SpringSecurityDemo01 on MacBook-Pro.local with PID 3312 (/Users/garen/Documents/workspace/spring-security-demo/spring-security-demo-01/target/classes started by garen in /Users/garen/Documents/workspace/spring-security-demo)
2022-09-28 23:02:34.535 INFO 3312 --- [ main] c.s.d.s.security.SpringSecurityDemo01 : No active profile set, falling back to default profiles: default
2022-09-28 23:02:35.447 INFO 3312 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-09-28 23:02:35.455 INFO 3312 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-09-28 23:02:35.455 INFO 3312 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]
2022-09-28 23:02:35.510 INFO 3312 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-09-28 23:02:35.510 INFO 3312 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 918 ms
2022-09-28 23:02:35.645 INFO 3312 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2022-09-28 23:02:35.860 INFO 3312 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: 255289cd-4302-4042-9fbb-db3723b9ac31
2022-09-28 23:02:35.979 INFO 3312 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@f14e5bf, org.springframework.security.web.context.SecurityContextPersistenceFilter@6b3871d6, org.springframework.security.web.header.HeaderWriterFilter@304a3655, org.springframework.security.web.csrf.CsrfFilter@5f14a673, org.springframework.security.web.authentication.logout.LogoutFilter@5d235104, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@b9dfc5a, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter@30404dba, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter@d176a31, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@1bc425e7, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@2eb79cbe, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@11a7ba62, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@3a91d146, org.springframework.security.web.session.SessionManagementFilter@12a160c2, org.springframework.security.web.access.ExceptionTranslationFilter@6dd93a21, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@7906578e]
2022-09-28 23:02:36.020 INFO 3312 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-09-28 23:02:36.029 INFO 3312 --- [ main] c.s.d.s.security.SpringSecurityDemo01 : Started SpringSecurityDemo01 in 1.783 seconds (JVM running for 2.439)
截屏2022-09-28 23.10.34.png用户名 user 密码控台出
网友评论