重点!!!
使用了new,比如使用controller调用一个工具类时,如果是在controller里面new的工具类,就会导致工具类中所有的@Value或者注入的对象都为null,
无法加载到容器中。
解决:去掉new改为注入@Autowired即可。
打包时application.properties没有在target下面。
解决方法:
在pom配置文件中的build里面加上如下内容:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>