1, spring-boot Study notes (a) Simple introduction

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.