002 Hello Spring Security

來源:互聯網
上載者:User

標籤:mil   string   font   author   1.0   標準   架構   oca   引用   

  在前面已經搭建過環境架構,現在在demo模組下寫一個簡單的案例,讓整個環境跑起來。

一:啟動Demo項目

1.建立類

  在這前,先建立包。

  

 

2.啟動類程式

 1 package com.cao; 2  3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 import org.springframework.web.bind.annotation.GetMapping; 6 import org.springframework.web.bind.annotation.RestController; 7  8 /** 9  * 模組啟動類10  * @author dell11  */12 @SpringBootApplication  //說明這是一個springboot項目13 @RestController            //可以提供rest服務14 public class ApplicationDemo {15 16     public static void main(String[] args) {17         //spring標準啟動方式18         SpringApplication.run(ApplicationDemo.class, args);19     }20     21     @GetMapping("/hello")22     public String hello() {23         return "spring secutity demo";24     }25 26 }

 

3.啟動效果

  說明沒有指定資料庫。

  

 

4.解決方式

  在core雖然引入了jdbc,但是沒有在項目中添加配置項。現在在demo模組中添加資料庫配置項

  建立File

    

  添加配置項

1 spring.datasource.driver-class-name = com.mysql.jdbc.Driver2 spring.datasource.url= jdbc:mysql://127.0.0.1:3308/test?useUnicode=yes&characterEncoding=UTF-8&useSSL=false3 spring.datasource.username = root4 spring.datasource.password = 123456

 

5.再次啟動

  session的儲存沒有指定。

  

 

6.解決方式

  在browser模組中有session引用,在這裡指定session的儲存為none

  

  在學習過程中,如果8080連接埠被佔用,可以在這裡配置一個配置(這裡使用8080,只是做一個樣本)

  

 

7.再次啟動,可以成功啟動

  

  這裡是預設,為了驗證demo,暫時將這個通過配置項關掉。

  

 

8.最終效果

  

 

9.此時的application.properties

 1 ##JDBC 2 spring.datasource.driver-class-name = com.mysql.jdbc.Driver 3 spring.datasource.url= jdbc:mysql://127.0.0.1:3308/test?useUnicode=yes&characterEncoding=UTF-8&useSSL=false 4 spring.datasource.username = root 5 spring.datasource.password = 123456 6  7 ##session store type 8 spring.session.store-type=none 9 10 ##server port11 #server.port=806012 13 ##security login14 security.basic.enabled = false

 

二:打包

1.在父項目上構建

  

 

2.觀看每個target

  可以發現,這個打包不能提供web服務,因為包太小。

  

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

  

 

3.如何打一個可以執行的包呢

  在demo模組中加一段build配置。

 1 <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"> 2   <modelVersion>4.0.0</modelVersion> 3   <artifactId>it-security-demo</artifactId> 4   <parent> 5       <groupId>com.jun.security</groupId> 6       <artifactId>it-security</artifactId> 7       <version>1.0.0-SNAPSHOT</version> 8       <relativePath>../it-security</relativePath> 9   </parent>10   11   <dependencies>12       <dependency>13             <groupId>com.jun.security</groupId>14             <artifactId>it-security-browser</artifactId>15             <version>${it.security.version}</version>16         </dependency>17   </dependencies>18   19   <build>20         <plugins>21             <plugin>22                 <groupId>org.springframework.boot</groupId>23                 <artifactId>spring-boot-maven-plugin</artifactId>24                 <version>1.3.3.RELEASE</version>25                 <executions>26                     <execution>27                         <goals>28                             <goal>repackage</goal>29                         </goals>30                     </execution>31                 </executions>32             </plugin>33         </plugins>34         <finalName>demo</finalName>35     </build>36 </project>

 

4.重新打包

  效果如下:

  

 

5.運行

  在命令列運行

  

 

6.最終啟動效果

  

 

002 Hello Spring Security

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.