Spring Security 学习-环境搭建(一)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ljk126wy/article/details/80968411

首先说明一下基础环境的配置:

JDK:1.8.0_144

IDE:STS(spring官方提供的基于eclipse的开发工具) :具体工具请自行搜索下载安装这里不做过多解释

1 搭建Spring Security基础聚合(多模块)和 继承 的父 maven项目 security

1.1 项目结构目录


1.2 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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.ljk</groupId>
  <artifactId>security</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <dependencyManagement>
  <dependencies>
       <dependency>
          <groupId>io.spring.platform</groupId>
          <artifactId>platform-bom</artifactId>
          <version>Brussels-SR11</version>
          <type>pom</type>
          <scope>import</scope>
      </dependency>
  </dependencies>
  </dependencyManagement>
       <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
       <modules>
       	<module>../security-demo</module>
       </modules>
</project>

这里我们采用Spring IO Platform 方便我们项目中版本管理 子的maven项目在添加依赖是无需写版本号

具体版本可以去spring官方查看:https://platform.spring.io/platform/#quick-start

我们这里选用版本:Brussels-SR11 :对应的springBoot版本是:1.5.14 spring Security:4.2.7


2 搭建Spring Security DEMO 测试项目(继承 security)

该项目是springBoot为基础的jar类型maven项目

2.1 项目的目录结构


其中:DemoApplication 是demo项目的启动类(springBoot)

package com.ljk.security;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {
	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
}

application.properties 是项目配置文件

server.context-path= /demo
server.port= 8086

2.2 demo的依赖

<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.ljk</groupId>
  <artifactId>security-demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
    <parent>
        <groupId>com.ljk</groupId>
        <artifactId>security</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../security</relativePath>
    </parent>
  <dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
	</dependencies>
 
  <build>
        <plugins>
            <!-- spring boot应用打包插件 -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.5.10.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

2 Spring Security hello word 测试

1 启动demo项目


红色框部分就是spring security 的默认密码


2 访问项目的内容通过spring security

打开游览器输入:http://localhost:8086/demo/index.html

index.html 在 demo项目的resources 目录下的resources 中



在输入框中登录名称输入user 密码就是我们启动时候控制台 using default security password 然后点击登录



显示出如下图表示测试成功!


如文章内容有误的情况欢迎邮件一起探讨 [email protected] 编写不易 看客勿喷






猜你喜欢

转载自blog.csdn.net/ljk126wy/article/details/80968411