SpringBoot
SpirngBoot
优点
- 简化配置
- 内嵌web容器(web容器就是一种服务程序,在服务器一个端口就有一个提供相应服务的程序,而这个程序就是处理从客户端发出的请求,如JAVA中的Tomcat容器,ASP的IIS或PWS都是这样的容器。一个服务器可以有多个容器。简单解释:就是处理请求的一个程序)
- 不需要写大量的配置信息xml
创建一个SpringBoot项目
-
包结构说明
![SpringBoot包结构说明]()
-
在pom.xml下导入依赖
![导入依赖]()
<!-- 依赖 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.7.RELEASE</version> <relativePath /> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> -
在java包下新建一个java类HelloController类
- 添加注解
@Controller(只返回页面,显示用)
@RestController(返回JSON格式的数据,基本都使用这种注解)
@RequestMapping(RequestMapping具体详解)
![第一个SpringBoot项目,HelloController]()
-
启动方式
- 添加@EnableAutoConfiguration注解,并在当前页面加入以下代码(一般不建议这样启动,了解即可)
public static void main(String[] args){ SpringApplication.run(HelloController.class,args); }![当前页面启动]()
-
新建一个Application类(注意:这个类要和所启动类在同一包下,否则需要添加@ComponentScan注解,并且指定其所要指向的包的类。)
添加@SpringBootApplication注解,然后添加main方法(默认扫描当前启动类所在的包里的对象)
![SpringBoot启动类]()
- SpringBoot类启动出现(Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package)请点击以下链接查看具体解决方法。 SpringBoot类启动问题






浙公网安备 33010602011771号