Spring配置遇到的问题

1.错误

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
log4j:WARN No appenders could be found for logger (freemarker.cache).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Spring 使用了Log4j 这个开源框架来输出信息,要解决这个问题非常简单,建立Log4j 的配置文件即可。在src 目录下创建配置文件,选择菜单File > New > File,文件名输入log4j.properties,文件内容如下所示:【只有加入了这个文件后才能看到Spring 后台完整的出错信息。在开发Spring 整合应用时,经常有人遇到出现404 错误但是却看不到任何出错信息的情况,这时你就需要检查一下这个文件是不是存在。】

    log4j.rootLogger=WARN, stdout
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender   
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

或者通过xml文件进行配置





<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

<appender name="org.zblog.all" class="org.apache.log4j.RollingFileAppender">



<param name="File" value="E:/study/log4j/all.output.log" /> 

<param name="Append" value="false" /> 

<param name="MaxBackupIndex" value="10" />

<layout class="org.apache.log4j.PatternLayout">

<param name="ConversionPattern" value="%p (%c:%L)- %m%n" /> 

layout>

appender>

<appender name="org.zblog.zcw" class="org.apache.log4j.RollingFileAppender">

<param name="File" value="E:/study/log4j/zhuwei.output.log" />

<param name="Append" value="true" />

<param name="MaxFileSize" value="10240" /> 

<param name="MaxBackupIndex" value="10" />

<layout class="org.apache.log4j.PatternLayout">

<param name="ConversionPattern" value="%p (%c:%L)- %m%n" />

layout>

appender>

<logger name="zcw.log"> 

<level value="debug" /> 

<appender-ref ref="org.zblog.zcw" /> 

logger>

<root> 

<appender-ref ref="org.zblog.all" /> 

root>

log4j:configuration>

2.错误

[mysql-cj-abandoned-connection-cleanup] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
 java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.

解决方法:查看tomcat–logs之后发现有错误:org/apache/commons/logging/LogFactory
需要在项目中导入commons-logging-1.2.jar

3.错误

Exception occurred during processing request: null 的错误原因以及解决办法
  • 配置applicationContext.xml,注入属性值
  • 对于Spring和Struts2整合的项目,struts.xml中的class属性要对应applicationContext.xml中注册的id值

你可能感兴趣的:(Spring)