首页 > 代码库 > SpringBoot 搭建
SpringBoot 搭建
1、使用Eclipse 建立Maven项目(webapp OR quickstart)
2、配置Maven,如下:
1 <parent> 2 <groupId>org.springframework.boot</groupId> 3 <artifactId>spring-boot-starter-parent</artifactId> 4 <version>1.2.5.RELEASE</version> 5 <relativePath/> 6 </parent> 7 8 <properties> 9 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 10 <java.version>1.8</java.version> 11 </properties> 12 13 <dependencies> 14 <dependency> 15 <groupId>org.springframework.boot</groupId> 16 <artifactId>spring-boot-starter-web</artifactId> 17 </dependency> 18 </dependencies> 19 20 <build> 21 <plugins> 22 <plugin> 23 <groupId>org.springframework.boot</groupId> 24 <artifactId>spring-boot-maven-plugin</artifactId> 25 </plugin> 26 </plugins> 27 </build>
3、建立启动Application
1 package demo.web.application; 2 import org.springframework.boot.SpringApplication; 3 import org.springframework.boot.autoconfigure.SpringBootApplication; 4 import org.springframework.context.annotation.ComponentScan; 5 6 @SpringBootApplication 7 @ComponentScan(basePackages={"demo.web.*"}) 8 public class Application { 9 public static void main(String[] args) { 10 SpringApplication.run(Application.class, args); 11 } 12 13 }
4、编辑Controller
1 package demo.web.controller; 2 import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 3 import org.springframework.web.bind.annotation.PathVariable; 4 import org.springframework.web.bind.annotation.RequestMapping; 5 import org.springframework.web.bind.annotation.RestController; 6 7 @RestController 8 @EnableAutoConfiguration 9 public class HelloController { 10 11 @RequestMapping("/") 12 String home() { 13 System.out.println("ee"); 14 return "Hello World!"; 15 } 16 17 @RequestMapping("/hello/{myName}") 18 String index(@PathVariable String myName) { 19 return "Hello "+myName+"!!!"; 20 } 21 22 }
5、通过application.properties对项目进行配置
server.port=9000
项目文件布局如下:
启动Application程序,即可访问网站。
SpringBoot 搭建
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。