Spring Security项目构建(一)

栏目: Java · 发布时间: 5年前

内容简介:依赖关系

源码地址

Github

项目构建

Spring Security项目构建(一)

依赖关系

Spring Security项目构建(一)

代码结构

  • security:主模块
  • security-core:核心业务逻辑
  • security-browser:浏览器安全特定代码
  • security-app:app相关特定代码
  • security-demo:样例程序

包引入

主模块

<?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.guosh.security</groupId>
    <artifactId>guosh-security</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <!--声明变量-->
    <properties>
        <guosh.security.version>1.0-SNAPSHOT</guosh.security.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.spring.platform</groupId>
                <artifactId>platform-bom</artifactId>
                <version>Brussels-SR16</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>
        </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> <!– 需要生成的目标class文件的编译版本 –>-->
                    <!--<encoding>UTF-8</encoding>-->
                <!--</configuration>-->
            <!--</plugin>-->
        <!--</plugins>-->
    <!--</build>-->

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

core模块

<?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">
    <parent>
        <artifactId>guosh-security</artifactId>
        <groupId>com.guosh.security</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>guosh-security-core</artifactId>
    <dependencies>
        <!--oauth2认证-->
        <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>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </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>

browser模块

<?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">
    <parent>
        <artifactId>guosh-security</artifactId>
        <groupId>com.guosh.security</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>guosh-security-browser</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.guosh.security</groupId>
            <artifactId>guosh-security-core</artifactId>
            <version>${guosh.security.version}</version>
        </dependency>
        <!--session集群-->
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session</artifactId>
        </dependency>
    </dependencies>

</project>

app 模块

<?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">
    <parent>
        <artifactId>guosh-security</artifactId>
        <groupId>com.guosh.security</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>guosh-security-app</artifactId>

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

demo 模块

<?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">
    <parent>
        <artifactId>guosh-security</artifactId>
        <groupId>com.guosh.security</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>guosh-security-demo</artifactId>


    <dependencies>
        <dependency>
            <groupId>com.guosh.security</groupId>
            <artifactId>guosh-security-browser</artifactId>
            <version>${guosh.security.version}</version>
        </dependency>
    </dependencies>


    <build>
        <!--demo是web程序需要运行打完包的名字-->
        <finalName>guoshsecurity</finalName>
        <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>
    </build>
</project>

Hello程序

现在需要把项目启动起来所以做了一个Demo

1.在Demo下面新建yml文件并连接数据库

server:
  port: 8080
  context-path: /guoshsecurity

spring:
  datasource:
    druid:
      url: jdbc:mysql://localhost:3306/guosecurity?useUnicode=true&characterEncoding=utf8&useSSL=true
      username: root
      password: root
      driver-class-name: com.mysql.jdbc.Driver
      #连接池初始化大小最小最大
      initial-size: 2
      min-idle: 2
      max-active: 2
      # 配置获取连接等待超时的时间
      maxWait: 60000
      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      timeBetweenEvictionRunsMillis: 60000
      # 配置一个连接在池中最小生存的时间,单位是毫秒
      minEvictableIdleTimeMillis: 60000
      testWhileIdle: true
      testOnBorrow: false
      testOnReturn: false
      # 打开PSCache,并且指定每个连接上PSCache的大小
      poolPreparedStatements: true
      maxPoolPreparedStatementPerConnectionSize: 20
      # 配置监控统计拦截的filters,去掉后监控界面 sql 无法统计,'wall'用于防火墙
      filters: stat,wall,log4j
      #属性来打开mergeSql功能;慢SQL记录
      connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
      #验证连接是否可用,使用的SQL语句
      validation-query: SELECT 1
      #合并多个DruidDataSource的监控数据
      useGlobalDataSourceStat: true
      #监控配置
      web-stat-filter:
        url-pattern: /*
        exclusions: /druid/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico
      stat-view-servlet:
        url-pattern: /druid/*
        login-username: guoadmin
        login-password: guoadmin
        #是否能按重制按键
        reset-enable: true
  #关闭spring session
  session:
    store-type: none
#先关闭security默认配置
security:
  basic:
    enabled: false

2.新建Spring boot的启动文件,添加一个/hello测试

Spring Security项目构建(一)

3.执行main函数查看

Spring Security项目构建(一)

4.打包测试

使用maven打包命令生成jar包之后可以使用

java  -jar  ./guoshsecurity.jar 启动

以上所述就是小编给大家介绍的《Spring Security项目构建(一)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

O2O进化论

O2O进化论

板砖大余、姜亚东 / 中信出版社 / 2014-5 / 49

在互联网的1.0时代,Online的商业和Offline的商业就像是两条平行线,没有交汇点,在移动浪潮下,他们正在交汇,这就是O2O(Online to Offline)。于是,人们认为:O2O就是线下将线上作为销售前台。结论是对的,但并非简单相加就可以达到。人们已经进入数据革命时期,O2O是线上和线下全流通的数据化工具,电子商务就是非数据商品的数据化。其次,O2O还是一种竞争格局。这决定了以O2......一起来看看 《O2O进化论》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具