002 Hello Spring Security
在前面已经搭建过环境框架,现在在demo模块下写一个简单的案例,让整个环境跑起来。
一:启动Demo项目
1.新建类
在这前,先建立包。

2.启动类程序
package com.cao; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; /**
* 模块启动类
* @author dell
*/
@SpringBootApplication //说明这是一个springboot项目
@RestController //可以提供rest服务
public class ApplicationDemo { public static void main(String[] args) {
//spring标准启动方式
SpringApplication.run(ApplicationDemo.class, args);
} @GetMapping("/hello")
public String hello() {
return "spring secutity demo";
} }
3.启动效果
说明没有指定数据库。

4.解决方式
在core虽然引入了jdbc,但是没有在项目中添加配置项。现在在demo模块中添加数据库配置项
新建File

添加配置项
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
spring.datasource.url= jdbc:mysql://127.0.0.1:3308/test?useUnicode=yes&characterEncoding=UTF-8&useSSL=false
spring.datasource.username = root
spring.datasource.password = 123456
5.再次启动
session的存储没有指定。

6.解决方式
在browser模块中有session引用,在这里指定session的存储为none

在学习过程中,如果8080端口被占用,可以在这里配置一个配置(这里使用8080,只是做一个示例)

7.再次启动,可以成功启动

这里是默认,为了验证demo,暂时将这个通过配置项关掉。

8.最终效果

9.此时的application.properties
##JDBC
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
spring.datasource.url= jdbc:mysql://127.0.0.1:3308/test?useUnicode=yes&characterEncoding=UTF-8&useSSL=false
spring.datasource.username = root
spring.datasource.password = 123456 ##session store type
spring.session.store-type=none ##server port
#server.port=8060 ##security login
security.basic.enabled = false
二:打包
1.在父项目上构建

2.观看每个target
可以发现,这个打包不能提供web服务,因为包太小。

-----------------------------------------------------------------------

3.如何打一个可以执行的包呢
在demo模块中加一段build配置。
<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>it-security-demo</artifactId>
<parent>
<groupId>com.jun.security</groupId>
<artifactId>it-security</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../it-security</relativePath>
</parent> <dependencies>
<dependency>
<groupId>com.jun.security</groupId>
<artifactId>it-security-browser</artifactId>
<version>${it.security.version}</version>
</dependency>
</dependencies> <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>demo</finalName>
</build>
</project>
4.重新打包
效果如下:

5.运行
在命令行运行

6.最终启动效果

002 Hello Spring Security的更多相关文章
- Spring Security OAuth2 开发指南
官方原文:http://projects.spring.io/spring-security-oauth/docs/oauth2.html 翻译及修改补充:Alex Liao. 转载请注明来源:htt ...
- spring mvc 和spring security配置 web.xml设置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmln ...
- SPRING SECURITY JAVA配置:Web Security
在前一篇,我已经介绍了Spring Security Java配置,也概括的介绍了一下这个项目方方面面.在这篇文章中,我们来看一看一个简单的基于web security配置的例子.之后我们再来作更多的 ...
- 【OAuth2.0】Spring Security OAuth2.0篇之初识
不吐不快 因为项目需求开始接触OAuth2.0授权协议.断断续续接触了有两周左右的时间.不得不吐槽的,依然是自己的学习习惯问题,总是着急想了解一切,习惯性地钻牛角尖去理解小的细节,而不是从宏观上去掌握 ...
- spring security oauth2.0 实现
oauth应该属于security的一部分.关于oauth的的相关知识可以查看阮一峰的文章:http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html ...
- Spring Security(08)——intercept-url配置
http://elim.iteye.com/blog/2161056 Spring Security(08)--intercept-url配置 博客分类: spring Security Spring ...
- Spring Security控制权限
Spring Security控制权限 1,配置过滤器 为了在项目中使用Spring Security控制权限,首先要在web.xml中配置过滤器,这样我们就可以控制对这个项目的每个请求了. < ...
- Spring Security笔记:Hello World
本文演示了Spring Security的最最基本用法,二个页面(或理解成二个url),一个需要登录认证后才能访问(比如:../admin/),一个可匿名访问(比如:../welcome) 注:以下内 ...
- Spring Security笔记:自定义Login/Logout Filter、AuthenticationProvider、AuthenticationToken
在前面的学习中,配置文件中的<http>...</http>都是采用的auto-config="true"这种自动配置模式,根据Spring Securit ...
随机推荐
- [PHP]flock文件IO锁的使用
一.flock概述 bool flock ( resource $handle , int $operation [, int &$wouldblock ] ) 参数 handle 文 ...
- Dnsmasq加速本地DNS请求
文章目录 Dnsmasq安装 Dnsmasq配置 Dnsmasq启动 Dnsmasq使用 Dnsmasq小结 默认的情况下,我们平时上网用的本地DNS服务器都是使用电信或者联通的,但是这样也导致了 ...
- Android:图解四种启动模式 及 实际应用场景解说
在一个项目中会包括着多个Activity,系统中使用任务栈来存储创建的Activity实例,任务栈是一种“后进先出”的栈结构.举个栗子,若我们多次启动同一个Activity.系统会创建多个实例依次放入 ...
- CSS学习——基础分类整理
1. CSS 层叠样式表: Cascading Style Sheets,定义如何显示html元素 CSS规则: 选择器{属性: 值; 属性: 值;} CSS注释: /*在这里写注释说 ...
- 用C#开发基于自动化接口的OPC客户端
OPC全称是Object Linking and Embedding(OLE) for Process Control,它的出现为基于Windows的应用程序和现场过程控制应用建立了桥梁.OPC作为一 ...
- pytorch的学习资源
安装:https://github.com/pytorch/pytorch 文档:http://pytorch.org/tutorials/beginner/blitz/tensor_tutorial ...
- django中数据库的配置及相关增删改查
ORM ORM是什么?:(在django中,根据代码中的类自动生成数据库的表也叫--code first) ORM:Object Relational Mapping(关系对象映射) 类名对应---- ...
- Linux用户、用户组、文件权限学习笔记
最近打算更仔细学习一下linux操作系统.先是恶补了一下用户.用户组.文件权限这三样比较重要的知识.学习这几样东西,得先掌握linux的权限系统相关知识.linux的权限系统主要是由用户.用户组和权限 ...
- LeetCode(90):子集 II
Medium! 题目描述: 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: [1,2,2] 输出: [ [2], [1 ...
- anaconda利用pip安装module
开始_程序 中搜索:anaconda prompt (控制台) 输入pip 出现pip的一些信息,可以忽略 接着输入 pip install 模块名称 例如:pip install alphalens ...