错误信息
在出现以下信息:
信息: Initializing Spring root WebApplicationContext log4j:WARN No appenders could be found for logger(org.springframework.web.context.ContextLoader). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http ://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
和服务器错误信息
web.xml的spring配置
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
只有以上的listener,但是它的文档写着
Bootstrap listener to start up and shut down Spring’s root WebApplicationContext. Simply delegates
to ContextLoader as well as to ContextCleanupListener.
This listener should be registered after org.springframework.web.util.Log4jConfigListener in web.xml,
if the latter is used.
As of Spring 3.1, ContextLoaderListener supports injecting the root web application context via the
ContextLoaderListener(WebApplicationContext) constructor, allowing for programmatic configuration
in Servlet 3.0+ environments. See org.springframework.web.WebApplicationInitializer for usage
examples.
需要修改的地方
- web.xml
<!-- config spring listener -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/configs/all.properties</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
把spring配置增加一个listener和其listener的配置文件,修改成这样就可以了,log4listener的配置文件内,添加如下的东西
- all.properties
# Set root logger level to error
log4j.rootLogger=INFO, Console, File
###### Console appender definition #######
# All outputs currently set to be a ConsoleAppender.
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{3}] %m%n
#log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n
###### File appender definition #######
log4j.appender.File=org.apache.log4j.DailyRollingFileAppender
log4j.appender.File.File=spring.log
log4j.appender.File.Append=false
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n
当然服务器不能常规启动,不只是配置的原因,这次的主要是由数据库连接被拒造成的,但做以上修改后,console就能出现错误日志如下,从而能一一排查错误
13:41:48,958 INFO [web.context.ContextLoader] Root WebApplicationContext: initialization started
13:41:49,067 INFO [context.support.XmlWebApplicationContext] Refreshing Root WebApplicationContext: startup date [Wed Nov 04 13:41:49 CST 2015]; root of context hierarchy
13:41:49,117 INFO [factory.xml.XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
13:41:49,440 INFO [factory.config.PropertyPlaceholderConfigurer] Loading properties file from ServletContext resource [/WEB-INF/configs/all.properties]
before controller afterPropertiesSe
13:41:49,551 INFO [v2.log.MLog] MLog clients using log4j logging.
13:41:49,720 INFO [v2.c3p0.C3P0Registry] Initializing c3p0-0.9.2.1 [built 20-March-2013 10:47:27 +0000; debug? true; trace: 10]
13:41:50,009 INFO [org.hibernate.Version] HHH000412: Hibernate Core {5.0.2.Final}
13:41:50,011 INFO [hibernate.cfg.Environment] HHH000206: hibernate.properties not found
13:41:50,012 INFO [hibernate.cfg.Environment] HHH000021: Bytecode provider name : javassist
13:41:50,069 INFO [annotations.common.Version] HCANN000001: Hibernate Commons Annotations {5.0.0.Final}
13:41:50,211 INFO [c3p0.impl.AbstractPoolBackedDataSource] Initializing c3p0 pool… com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1k67t389c1lzsplk14o06b0|1dbed0, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1k67t389c1lzsplk14o06b0|1dbed0, idleConnectionTestPeriod -> 0, initialPoolSize -> 1, jdbcUrl -> jdbc:mysql://127.0.0.1:3306/ntci, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 20, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 1, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {user=*, password=*}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
13:42:21,818 WARN [v2.resourcepool.BasicResourcePool] com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@e23d8 – Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: Access denied for user ‘tester’@’localhost’ (using password: YES)