在前面已经搭建过环境框架,现在在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的更多相关文章

  1. Spring Security OAuth2 开发指南

    官方原文:http://projects.spring.io/spring-security-oauth/docs/oauth2.html 翻译及修改补充:Alex Liao. 转载请注明来源:htt ...

  2. spring mvc 和spring security配置 web.xml设置

    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmln ...

  3. SPRING SECURITY JAVA配置:Web Security

    在前一篇,我已经介绍了Spring Security Java配置,也概括的介绍了一下这个项目方方面面.在这篇文章中,我们来看一看一个简单的基于web security配置的例子.之后我们再来作更多的 ...

  4. 【OAuth2.0】Spring Security OAuth2.0篇之初识

    不吐不快 因为项目需求开始接触OAuth2.0授权协议.断断续续接触了有两周左右的时间.不得不吐槽的,依然是自己的学习习惯问题,总是着急想了解一切,习惯性地钻牛角尖去理解小的细节,而不是从宏观上去掌握 ...

  5. spring security oauth2.0 实现

    oauth应该属于security的一部分.关于oauth的的相关知识可以查看阮一峰的文章:http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html ...

  6. Spring Security(08)——intercept-url配置

    http://elim.iteye.com/blog/2161056 Spring Security(08)--intercept-url配置 博客分类: spring Security Spring ...

  7. Spring Security控制权限

    Spring Security控制权限 1,配置过滤器 为了在项目中使用Spring Security控制权限,首先要在web.xml中配置过滤器,这样我们就可以控制对这个项目的每个请求了. < ...

  8. Spring Security笔记:Hello World

    本文演示了Spring Security的最最基本用法,二个页面(或理解成二个url),一个需要登录认证后才能访问(比如:../admin/),一个可匿名访问(比如:../welcome) 注:以下内 ...

  9. Spring Security笔记:自定义Login/Logout Filter、AuthenticationProvider、AuthenticationToken

    在前面的学习中,配置文件中的<http>...</http>都是采用的auto-config="true"这种自动配置模式,根据Spring Securit ...

随机推荐

  1. 轻松搞懂elasticsearch概念

      本文主要介绍elasticsearch6.0的一些基本概念,有助于深入理解.研究elasticsearch和elk系统 一图胜千言 elasticsearch与mysql参照来看 添加一条数据 紫 ...

  2. CodeCraft-19 and Codeforces Round #537 (Div. 2) 题解

    传送门 D. Destroy the Colony 首先明确题意:除了规定的两种(或一种)字母要在同侧以外,其他字母也必须在同侧. 发现当每种字母在左/右边确定之后,方案数就确定了,就是分组的方案数乘 ...

  3. 【MySql】delete用法

    delete 语句用于删除表中的数据, 基本用法为: delete from 表名称 where 删除条件; 以下是在表 students 中的实例: 删除 id 为 3 的行: delete fro ...

  4. Confluence 6 识别慢性能的宏

    Page Profiling 给你了有关页面在载入的时候操作缓慢的邪教,你可以将下面的内容添加到调试(debug)级别: Version 3.1 及其后续版本 设置包名字为 com.atlassian ...

  5. Confluence 6 使用电子邮件可见

    Confluence 提供了 3 个电子邮件策略,这些策略 Confluence 管理员可以通过管理员控制台(Administration Console)进行配置: 公开(Public):电子邮件地 ...

  6. 访问 Confluence 6 的计划任务配置

    希望访问 Confluence 计划任务配置界面: 进入  > 基本配置(General Configuration) > 计划任务(Scheduled Jobs) 所有的计划任务将会按照 ...

  7. Confluence 6 布局高级自定义

    重载 Velocity 模板 velocity 目录是 Confluence Velocity 模板文件进行搜索时候需要的文件夹.例如,你可以通过将你的 Velocity 文件使用正确的文件名放置到正 ...

  8. Confluence 6 自定义配色方案

    Confluence 的管理员可以修改 Confluence 的色彩配色方案.站点的默认配色方案将会在站点的默认空间上同时生效. 希望修改站点的配色方案: 在屏幕的右上角单击 控制台按钮 ,然后选择  ...

  9. npx简介(转载)

    npm v5.2.0引入的一条命令(npx),引入这个命令的目的是为了提升开发者使用包内提供的命令行工具的体验. 举例:使用create-react-app创建一个react项目. 老方法: npm ...

  10. vue-cli 里axios的使用

    1.axios的安装 cnpm i axios --save 2.axios的引入 安装其他插件的时候,可以直接在 main.js 中引入并 Vue.use(),但是 axios 并不能 use,只能 ...