1.先创建一个maven项目;
2.把下面这些东西放到pom文件中,还没研究这些东西的作用,先跑起来再说
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.BUILD-SNAPSHOT</version>
</parent>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!-- Add Spring repositories -->
<!-- (you don't need this if you are using a .RELEASE version) -->
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
3.创建一个Application.class;
1)在类上面注解一个@SrpingBootApplication,应该是要标记这个类用来作为spring自动配置的入口
2)编写main函数,作为启动springboot的入口,因为spring一直都不需要使用tomcat,自己就是一个容器,并且性能高于tomcat,进程只占少量内存,而tomcat启动就需要占用好几百M的内存
3)以下是main函数代码
SpringApplication.run(Application.class, args);
4.编写mvc中的controller层,以前都是用struts2,对srping的control层有点生疏,以下是UserAction.class代码
@RestController
@EnableAutoConfiguration
public class UserAction{
@RequestMapping("/")
public String index(){
return "springboot"
}
@RequestMapping("/hello")
public String hello(){
return "hello spring boot";
}
}
5.开始run Application.class中的main方法就可以了