In front of the environment framework has been built, now in the demo module to write a simple case, let the whole environment run up.
One: Start the demo project
1. New class
Before this, build the package first.
2. Start the class program
1 PackageCom.cao;2 3 Importorg.springframework.boot.SpringApplication;4 Importorg.springframework.boot.autoconfigure.SpringBootApplication;5 Importorg.springframework.web.bind.annotation.GetMapping;6 ImportOrg.springframework.web.bind.annotation.RestController;7 8 /**9 * Module Startup classTen * @authorDell One */ A@SpringBootApplication//Description This is a springboot project -@RestController//can provide rest services - Public classApplicationdemo { the - Public Static voidMain (string[] args) { - //Spring Standard boot mode -Springapplication.run (Applicationdemo.class, args); + } - +@GetMapping ("/hello") A PublicString Hello () { at return"Spring secutity Demo"; - } - -}
3. Start effect
The description does not specify a database.
4. How to Solve
Although JDBC was introduced in the core, no configuration items were added to the project. Now add the database configuration item in the Demo module
New file
Add a configuration item
1 spring.datasource.driver-class-name = Com.mysql.jdbc.Driver 2 spring.datasource.url= jdbc:mysql://127.0.0.1:3308/test?useunicode=yes&characterencoding =utf-8&usessl=false3spring.datasource.username = root4 Spring.datasource.password = 123456
5. Start again
The store for session is not specified.
6. How to Solve
There is a session reference in the browser module, where the session is stored as none
In the learning process, if the 8080 port is occupied, you can configure a configuration here (use 8080 here, just to do an example)
7. Start again to start successfully
Here is the default, in order to verify the demo, temporarily disable this through the configuration item.
8. Final effect
9. The application.properties at this time
1 # #JDBC2 spring.datasource.driver-class-name = Com.mysql.jdbc.Driver3Spring.datasource.url= Jdbc:mysql://127.0.0.1:3308/test?useunicode=yes&characterencoding=utf-8&usessl=false4 spring.datasource.username = root5 Spring.datasource.password = 1234566 7 # #session Store Type8 Spring.session.store-type=none9 Ten # #server Port One #server. port=8060 A - # #security Login -Security.basic.enabled = False
Two: Packaging
1. Build on the parent project
2. Watch each target
It can be found that this package does not provide a Web service because the package is too small.
-----------------------------------------------------------------------
3. How do I make a package that can be executed?
Add a build configuration to the demo module.
1 <Projectxmlns= "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>Ten One <Dependencies> A <Dependency> - <groupId>Com.jun.security</groupId> - <Artifactid>It-security-browser</Artifactid> the <version>${it.security.version}</version> - </Dependency> - </Dependencies> - + <Build> - <Plugins> + <plugin> A <groupId>Org.springframework.boot</groupId> at <Artifactid>Spring-boot-maven-plugin</Artifactid> - <version>1.3.3.RELEASE</version> - <executions> - <Execution> - <Goals> - <goal>Repackage</goal> in </Goals> - </Execution> to </executions> + </plugin> - </Plugins> the <Finalname>Demo</Finalname> * </Build> $ </Project>
4. Repackaging
The effect is as follows:
5. Running
Run at the command line
6. Final Start effect
002 Hello Spring Security