SpringBoot + SpringSecurity 环境搭建的步骤
程序员文章站
2023-12-19 10:19:04
一、使用springboot+maven搭建一个多模块项目(可以参考这篇文章 --> )
二、删除父工程的src文件,删除app、browser、core下的....
一、使用springboot+maven搭建一个多模块项目(可以参考这篇文章 --> )
二、删除父工程的src文件,删除app、browser、core下的.java文件
依赖关系:
- demo 依赖 browser
- browser、app依赖core
三、父工程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> <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文件
<?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文件
<?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文件
<?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文件
<?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
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启动类上添加测试接口
@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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。