<profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile>
浏览器发送hello请求,服务器接受请求并处理,响应Hello World字符串;
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
package com.xdr; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /* @SpringBootApplication 来标注一个主程序 */ @SpringBootApplication public class HelloWorldApplication { public static void main(String[] args) { System.out.println("启动springboot程序"); SpringApplication.run(HelloWorldApplication.class, args); } }
package com.xdr.com.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class Controller { @RequestMapping("hello") public String sayHello(){ return "Hello SpringBoot"; } }
在resource下创建application.properties文件写入
server.port=8082
把端口号改为8082,以免跟8080冲突
访问项目
<!-- 这个插件,可以将应用打包成一个可执行的jar包;--> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
将这个应用打成jar包,直接使用java -jar xxx.jar(xxx表示jar包的名称)的命令进行执行;
在idea自带Maven打包中
刷新项目: