First, the new general Maven project
Pom.xml
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> <relativePath/> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> <finalName>SpringBoot001_HelloWorld</finalName> </build>
Second, write the code
@SpringBootApplication@RestControllerpublic class Application{ @RequestMapping("/hello") public String hello(){ return "hello world"; } @RequestMapping("/geeting") public String geeting(){ return "Index page"; } @RequestMapping("/geeting/{user}") public String get(@PathVariable("user") String name ){ if(name.equals("zhangsan")){ return name+" Hello"; } return "hello"; } public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
* * @SpringBootApplication * *: Specifies whether the Springboot app
* * @RestContrller * *: This is generally added to the class, indicating that this is a rest application, each method returned is no longer a view
* * @RequestMapping * *: URL path mapping
* * @PathVariable * *: The value of the variable in the read path is assigned to name
Third, code execution
Execute the Java-jar jar package path on the command line by MVN the package directly first
The following content as an understanding; wait till the century is applied.
Iv. Cessation of
1), forced stop
ps aux | grep spring | xargs kill -9
2), stop through the front desk
Pom file Join
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId></dependency>
Application.yml Join
#启用shutdownendpoints: shutdown: enabled: true#禁用密码验证 sensitive: false
3), add password Authentication
Pom.xml Join
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId></dependency>
Application.properties Join
#开启shutdown的安全验证endpoints.shutdown.sensitive=true#验证用户名security.user.name=admin#验证密码security.user.password=admin#角色management.security.role=SUPERUSER# 指定端口management.port=8081# 指定地址management.address=127.0.0.1
4) Close command
curl -u admin:admin -X POST http://127.0.0.1:8081/manage/shutdown# Demo$ curl -u admin:admin -X POST http://127.0.0.1:8081/manage/shutdown{"message":"Shutting down, bye..."}
1, spring-boot Study notes (a) Simple introduction