问题记录:
1. Spring java配置及注解注入方法出现空指针异常的原因
当通过new的方式创建一个对象的时候,虽然期望使用了注解@Autowired对这个对象进行装配,但是Spring是不会这么做的,因为Spring不会对任意一个new 出来的对象进行自动装配,只有这个对象也是一个在Spring中注册过的Bean,才会获得自动装配的功能。
2、Tomcat启动后,日志出现中文乱码的规避操作
修改tomcat/conf/logging.properties中如下配置:
java.util.logging.ConsoleHandler.encoding = utf-8
更改为
java.util.logging.ConsoleHandler.encoding = GBK
3、Tomcat启动,提示找不到XXX.xml
运用IDEA本地选择Tomcat Server 来debug工程,报错
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
进入到Project Structure中,查看工程的war:exploded中的Output directory,确认war包被输出到webapps中,
然后去到该路径下,查看WEB-INF\classes中是否包含了缺少的applicationContext.xml,
如果确认缺少,则说明打war包的时候,没有将这个文件打到war包中,需要关注工程中pom.xml中build中,是否对resource进行了排出;
比如:
<resources>
<resource>
<directory>resources</directory>
<excludes>
<exclude>*</exclude>
</excludes>
</resource>
</resources>