3.1新建一个包,创建一个控制器,如图:
3.2、访问第一个 控制器TestController,并且请求 getHello的时候,返回了 hellospringboot,但是访问新建包的TestControllerdemo的时候,请求getHellodemo,却失败了,原因是没有扫描到新建的包的控制器,如图:
3.3、注释的介绍:
package com.springboot.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; @SpringBootApplication //springbootApplication注解会自动扫描当前包下所有的spring注解,以及当前包下所有的子包下的spring注解 @ComponentScan(value = "com.springboot.demo2.controller") public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } 将扫描包的注释加上之后,再次访问成功;如图:4.1 热部署的步骤
在pom文件加入devtools插件,在 spring-boot-maven-plugin下增加开启热部署的标签
<!--添加热部署的插件--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!--开启热部署支持--> <configuration> <fork>true</fork> </configuration> </plugin> </plugins> <!--将源码目录中的xml文件一起打包发布--> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> </includes> </resource> </resources> </build>如果做以上配置不生效: 1.开启idea自动make功能 ①:Settings -compile-> 查找make|bulid project automatically --> 选中 ②:ctrl+shift+A --->查找Registry --> 找到并勾选compiler.automake.allow.when.app.running 或者 ctrl+shift+alt+/