服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|JavaScript|易语言|

服务器之家 - 编程语言 - Java教程 - SpringBoot + SpringSecurity 环境搭建的步骤

SpringBoot + SpringSecurity 环境搭建的步骤

2021-05-05 11:03zekeTao Java教程

这篇文章主要介绍了SpringBoot + SpringSecurity 环境搭建的步骤,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

一、使用springboot+maven搭建一个多模块项目(可以参考这篇文章 --> 这里)

SpringBoot + SpringSecurity 环境搭建的步骤

二、删除父工程的src文件,删除app、browser、core下的.java文件

依赖关系:

  1. demo 依赖 browser
  2. browser、app依赖core

三、父工程pom.xml文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?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>
 
  <groupid>com.zeke</groupid>
  <artifactid>zeke-security</artifactid>
  <version>0.0.1-snapshot</version>
  <packaging>pom</packaging>
  <name>zeke-security</name>
 
  <properties>
    <zeke-security-version>1.0-snapshot</zeke-security-version>
  </properties>
 
  <modules>
    <module>zeke-security-app</module>
    <module>zeke-security-browser</module>
    <module>zeke-security-core</module>
    <module>zeke-security-demo</module>
  </modules>
 
  <dependencies>
    <dependency>
      <groupid>junit</groupid>
      <artifactid>junit</artifactid>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupid>org.springframework.boot</groupid>
      <artifactid>spring-boot-test</artifactid>
      <version>1.5.8.release</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
 
  <dependencymanagement>
    <dependencies>
      <dependency>
        <groupid>io.spring.platform</groupid>
        <artifactid>platform-bom</artifactid>
        <version>brussels-sr6</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupid>org.springframework.cloud</groupid>
        <artifactid>spring-cloud-dependencies</artifactid>
        <version>dalston.sr5</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupid>org.springframework.boot</groupid>
        <artifactid>spring-boot-configuration-processor</artifactid>
        <optional>true</optional>
      </dependency>
    </dependencies>
  </dependencymanagement>
 
  <build>
    <plugins>
      <plugin>
        <groupid>org.apache.maven.plugins</groupid>
        <artifactid>maven-compiler-plugin</artifactid>
        <version>2.3.2</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <encoding>utf-8</encoding>
        </configuration>
      </plugin>
    </plugins>
  </build>
 
</project>

四、zeke-security-demo项目下的pom.xml文件 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?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>com.zeke</groupid>
    <artifactid>zeke-security</artifactid>
    <version>0.0.1-snapshot</version>
  </parent>
 
  <artifactid>zeke-security-demo</artifactid>>
 
  <dependencies>
    <dependency>
      <groupid>com.zeke</groupid>
      <artifactid>zeke-security-browser</artifactid>
      <version>${zeke-security-version}</version>
    </dependency>
    <dependency>
      <groupid>junit</groupid>
      <artifactid>junit</artifactid>
      <version>4.12-beta-3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupid>org.springframework.boot</groupid>
      <artifactid>spring-boot-starter-aop</artifactid>
    </dependency>
    <dependency>
      <groupid>commons-io</groupid>
      <artifactid>commons-io</artifactid>
    </dependency>
 
    <!-- swagger -->
    <dependency>
      <groupid>io.springfox</groupid>
      <artifactid>springfox-swagger2</artifactid>
      <version>2.7.0</version>
    </dependency>
    <dependency>
      <groupid>io.springfox</groupid>
      <artifactid>springfox-swagger-ui</artifactid>
      <version>2.7.0</version>
    </dependency>
 
    <!-- wiremock -->
    <dependency>
      <groupid>com.github.tomakehurst</groupid>
      <artifactid>wiremock</artifactid>
      <version>2.14.0</version>
    </dependency>
    <dependency>
      <groupid>org.springframework</groupid>
      <artifactid>spring-test</artifactid>
      <version>4.3.12.release</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupid>org.springframework</groupid>
      <artifactid>spring-test</artifactid>
      <version>4.3.12.release</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupid>org.springframework</groupid>
      <artifactid>spring-test</artifactid>
      <version>4.3.12.release</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
 
  <build>
    <plugins>
      <plugin>
        <groupid>org.springframework.boot</groupid>
        <artifactid>spring-boot-maven-plugin</artifactid>
        <version>1.5.6.release</version>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
    <finalname>demo</finalname>
  </build>
</project>

五、zeke-security-core项目下的pom.xml文件 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?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>
    <artifactid>zeke-security</artifactid>
    <groupid>com.zeke</groupid>
    <version>0.0.1-snapshot</version>
  </parent>
 
  <artifactid>zeke-security-core</artifactid>
 
  <dependencies>
    <dependency>
      <groupid>org.springframework.cloud</groupid>
      <artifactid>spring-cloud-starter-oauth2</artifactid>
    </dependency>
    <!--<dependency>-->
    <!--<groupid>org.springframework.boot</groupid>-->
    <!--<artifactid>spring-boot-starter-data-redis</artifactid>-->
    <!--</dependency>-->
    <dependency>
      <groupid>org.springframework.boot</groupid>
      <artifactid>spring-boot-starter-jdbc</artifactid>
    </dependency>
    <dependency>
      <groupid>mysql</groupid>
      <artifactid>mysql-connector-java</artifactid>
    </dependency>
    <dependency>
      <groupid>org.springframework.social</groupid>
      <artifactid>spring-social-config</artifactid>
    </dependency>
    <dependency>
      <groupid>org.springframework.social</groupid>
      <artifactid>spring-social-core</artifactid>
    </dependency>
    <dependency>
      <groupid>org.springframework.social</groupid>
      <artifactid>spring-social-security</artifactid>
    </dependency>
    <dependency>
      <groupid>org.springframework.social</groupid>
      <artifactid>spring-social-web</artifactid>
    </dependency>
    <dependency>
      <groupid>commons-lang</groupid>
      <artifactid>commons-lang</artifactid>
    </dependency>
    <dependency>
      <groupid>commons-collections</groupid>
      <artifactid>commons-collections</artifactid>
    </dependency>
    <dependency>
      <groupid>commons-beanutils</groupid>
      <artifactid>commons-beanutils</artifactid>
    </dependency>
  </dependencies>
</project>

六、zeke-security-browser项目下的pom.xml文件 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?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>com.zeke</groupid>
    <artifactid>zeke-security</artifactid>
    <version>0.0.1-snapshot</version>
  </parent>
 
  <artifactid>zeke-security-browser</artifactid>
 
  <dependencies>
    <dependency>
      <groupid>com.zeke</groupid>
      <artifactid>zeke-security-core</artifactid>
      <version>${zeke-security-version}</version>
    </dependency>
    <dependency>
      <groupid>org.springframework.session</groupid>
      <artifactid>spring-session</artifactid>
    </dependency>
  </dependencies>
</project>

七、zeke-security-app项目下的pom.xml文件 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?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>
    <artifactid>zeke-security</artifactid>
    <groupid>com.zeke</groupid>
    <version>0.0.1-snapshot</version>
  </parent>
 
  <artifactid>zeke-security-app</artifactid>
 
  <dependencies>
    <dependency>
      <groupid>com.zeke</groupid>
      <artifactid>zeke-security-core</artifactid>
      <version>${zeke-security-version}</version>
    </dependency>
  </dependencies>
</project>

八、zeke-security-demo项目下的application.properties

?
1
2
3
4
5
6
7
spring.datasource.driver-class-name=com.mysql.jdbc.driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/imooc-demo
spring.datasource.username=root
spring.datasource.password=
 
spring.session.store-type=none
security.basic.enabled=false

九、在zeke-security-demo启动类上添加测试接口

?
1
2
3
4
5
6
7
8
9
10
11
12
13
@restcontroller
@springbootapplication
public class zekesecuritydemoapplication {
 
  public static void main(string[] args) {
    springapplication.run(zekesecuritydemoapplication.class, args);
  }
 
  @getmapping("/hello")
  public string hello(){
    return "success";
  }
}

十、输入地址localhost/hello

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/zeketao/article/details/79522968

延伸 · 阅读

精彩推荐