Spring Security(一):10分钟搭建项目结构

本文介绍了Spring Security项目的搭建。先说明了Spring Security可参考官方文档,接着阐述构建工程所需工具和环境,如STS工具、jdk1.8以上、maven3.5+等。详细讲解了项目结构,包括主模块和其他模块创建,各模块pom.xml配置修改,最后介绍了构建打包的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Spring Security 是什么?


详情参考 Spring Security官方文档

 

构建工程


  1. 下载 STS(Spring Tool suite)  工具(建议),或者使用Eclipse (http://start.spring.io/  构造Generate Project并下载项目压缩包,然后导入到Eclipse
  2. jdk1.8或以上
  3. maven3.5+
  4. mysql

 

项目结构


一、zjj-security:主模块

创建 maven 主模块工程 zjj-security【注:主模块工程,打包方式 packaging 选择 pom,其他工程选择jar】  

STS ->  New -> New Maven Project (并勾选 Create a simple project 选项)


 

二、其他模块

使用 maven 分别创建其他四个工程:zjj-security-core、zjj-security-app、zjj-security-browser、zjj-security-demo【注:打包方式 packaging 选择jar】  

STS ->  New -> New Maven Project (并勾选 Create a simple project 选项)

 

三、zjj-security主项目pom.xml配置修改

1、<properties><zjj.security.version></...>指定全局版本号

2、<dependencies>加入管理依赖版本

3、<plugin> 加入maven 编译插件,统一版本及编码

4、打开pom.xml 选择底部Overview->Modules->Add 将其他几个项目作为子模块关联进去

<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.zjj.security</groupId>
	<artifactId>zjj-security</artifactId>
	<version>1.0</version>
	<packaging>pom</packaging>
	
	<properties>
		<zjj.security.version>1.0</zjj.security.version>
	</properties>

	<dependencyManagement>
		<dependencies>
			<!-- https://docs.spring.io/platform/docs/Brussels-SR4/reference/htmlsingle/ -->
			<!-- 管理依赖版本 -->
			<dependency>
				<groupId>io.spring.platform</groupId>
				<artifactId>platform-bom</artifactId>
				<version>Brussels-SR4</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>

			<!-- https://cloud.spring.io/spring-cloud-static/Dalston.SR2/single/spring-cloud.html -->
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>Dalston.SR2</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			<!-- maven 编译插件,统一版本 -->
			<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>

	<modules>
		<module>../zjj-security-app</module>
		<module>../zjj-security-browser</module>
		<module>../zjj-security-core</module>
		<module>../zjj-security-demo</module>
	</modules>
</project>

 

四、zjj-security-core pom.xml配置修改

<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>zjj-security-core</artifactId>
	<parent>
		<groupId>com.zjj.security</groupId>
		<artifactId>zjj-security</artifactId>
		<version>1.0</version>
		<relativePath>../zjj-security</relativePath>
	</parent>

	<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>
		
		<!--  social 相关 第三方登录需要用到 -->
		<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>

 

五、zjj-security-app pom.xml配置修改

<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>zjj-security-app</artifactId>
	<parent>
		<groupId>com.zjj.security</groupId>
		<artifactId>zjj-security</artifactId>
		<version>1.0</version>
		<relativePath>../zjj-security</relativePath>
	</parent>

	<dependencies>
		<dependency>
			<groupId>com.zjj.security</groupId>
			<artifactId>zjj-security-core</artifactId>
			<version>${zjj.security.version}</version>
		</dependency>
	</dependencies>
</project>

 

六、zjj-security-browser pom.xml配置修改

<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>zjj-security-browser</artifactId>
	<parent>
		<groupId>com.zjj.security</groupId>
		<artifactId>zjj-security</artifactId>
		<version>1.0</version>
		<relativePath>../zjj-security</relativePath>
	</parent>

	<dependencies>
		<dependency>
			<groupId>com.zjj.security</groupId>
			<artifactId>zjj-security-core</artifactId>
			<version>${zjj.security.version}</version>
		</dependency>
		
		<!-- 需要引用session会话管理 -->
		<dependency>
		    <groupId>org.springframework.session</groupId>
		    <artifactId>spring-session</artifactId>
		</dependency>
	</dependencies>
</project>

 

七、zjj-security-demo pom.xml配置修改

<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>zjj-security-demo</artifactId>
	<parent>
		<groupId>com.zjj.security</groupId>
		<artifactId>zjj-security</artifactId>
		<version>1.0</version>
		<relativePath>../zjj-security</relativePath>
	</parent>
	<dependencies>
		<dependency>
			<groupId>com.zjj.security</groupId>
			<artifactId>zjj-security-browser</artifactId>
			<version>${zjj.security.version}</version>
		</dependency>
		
		<!-- 单元测试 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
		</dependency>
	</dependencies>

	<!-- 引入插件 spring-boot-maven-plugin 将项目打成独立jar包 -->
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<version>1.3.3.RELEASE</version>
				<executions>
					<execution>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
		<finalName>zjj-demo</finalName>
	</build>
</project>

 

八、构建打包

找到zjj-security工程,点击右键-》选择Run as -》maven build ... -》 Goals 填写 clean package 命令 -》 点击 Run 执行,控制台打印:

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] zjj-security ....................................... SUCCESS [  0.350 s]
[INFO] zjj-security-core .................................. SUCCESS [ 11.229 s]
[INFO] zjj-security-app ................................... SUCCESS [  0.155 s]
[INFO] zjj-security-browser ............................... SUCCESS [  1.399 s]
[INFO] zjj-security-demo .................................. SUCCESS [  6.424 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

更多内容请关注我的个人博客:http://www.zjjfx68.com/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值