- 创建一个 maven 项目(可使用 idea 或者其他编辑器)
mvn archetype:generate -DgroupId=com.edurt -DartifactId=springboot-security-integration -DarchetypeArtifactId=maven-archetype-quickstart -Dversion=1.0.0 -DinteractiveMode=false
等待下载依赖, 完成项目的创建, 完成后将项目导入编辑器中.
- 在项目的 pom 文件中引入需要的springboot 和 security 依赖
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<groupId>com.edurt</groupId>
<artifactId>springboot-security-integration</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>springboot-security-integration</name>
<url>http://maven.apache.org</url>
<properties>
<system.java.version>1.8</system.java.version>
<!-- 依赖 -->
<!-- 插件 -->
<plugin.springboot.version>1.5.9.RELEASE</plugin.springboot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 引入 security 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- 引入热部署依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${plugin.springboot.version}</version>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
- 修改 App 类使其支持 springboot 程序
package com.edurt;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Hello world!
*/
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
- 测试运行检查应用是否支持 springboot 属性, 删除 test 包下的 AppTest 类
mvn spring-boot:run
此时我们的 springboot 应用程序已经搭建完成. 浏览器打开 http://localhost:8080 出现以下授权页面即可