SpringBoot配置与启动

Eclipse
1、空白处右键--new--other--Maven project
选择webapp
设置group id呵artifact id

2、pom.xml初始配置
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
com.test
SpringBootTest2
war
0.0.1-SNAPSHOT
SpringBootTest2 Maven Webapp
http://maven.apache.org
junit
junit
3.8.1
test
SpringBootTest2
添加配置
org.springframework.boot
spring-boot-starter-parent
1.5.2.RELEASE
lookup parent from repository

UTF-8
UTF-8
1.8
修改打包格式类型为jar(对pom.xml修改后项目图标报错,右键--Run As--Maven clean,项目右键--maven--update project 解决问题)
添加Spring boot配置
Spring Boot 启动父依赖
Spring Boot web依赖
Controller内容
package com.test.web;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/testing")
public class TestController {
@RequestMapping(value = "/get_info", method = { RequestMethod.GET })
//http://localhost:8090/testing/get_info
public String hello(){
System.out.println("HELLO");
return "HELLO";
}
@GetMapping("/world")
//http://localhost:8090/testing/world
public String world() {
return "WORLD";
}
}


application内容
package com.test;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}

}
application.properties 配置文件
server.port=8090

启动
访问
http://localhost:8090/testing/get_info
http://localhost:8090/testing/world

SpringBoot 打成jar包文件pom.xml添加配置
SpringBootTest2
org.springframework.boot
spring-boot-maven-plugin

org.apache.maven.plugins
maven-shade-plugin
3.0.0
*:*
META-INF/*.SF
META-INF/*.DSA
META-INF/*.RSA
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
com.test.TestApplication

你可能感兴趣的:(SpringBoot)