package com.example.demo1.controller;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Component
@RequestMapping("/v1")
public class HelloController {
final static Logger log = LogManager.getLogger(HelloController.class);
@Value("${server.port}")
private int port ;
@RequestMapping(value = "", method = RequestMethod.GET)
public String test() {
return "invoke url /,port="+port;
}
@RequestMapping(value = "/test1", method = RequestMethod.GET)
public String test1() {
return "invoke url /test1,port="+port;
}
@RequestMapping(value = "/test2", method = RequestMethod.GET)
public String test2() {
return "invoke url /test2,port="+port;
}
}
3、编写一个启动类
package com.example.demo1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Demo1Application {
public static void main(String[] args) {
SpringApplication.run(Demo1Application.class, args);
}
}
4、我用到的pom文件
4.0.0org.springframework.bootspring-boot-starter-parent2.7.6com.exampledemo10.0.1-SNAPSHOTdemo1Demo project for Spring Boot1.82.19.0org.springframework.bootspring-boot-starterorg.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-loggingorg.springframework.bootspring-boot-starter-testorg.apache.logging.log4jlog4j-api${log4j.version}org.apache.logging.log4jlog4j-core${log4j.version}org.apache.maven.pluginsmaven-compiler-plugin3.7.01.81.8UTF-8org.apache.maven.pluginsmaven-assembly-plugin2.5.5com.example.demo1.Demo1Applicationjar-with-dependenciesmake-assemblypackagesingle