junit可执行但控制层无法执行_Junit测试时ContextLoader.getCurrentWebApplicationContext()返回空值...
Junit測試時,test類調(diào)用manage類,manage類調(diào)用dao類
dao類的代碼中有如下語句:ContextLoader.getCurrentWebApplicationContext()
執(zhí)行這條語句時返回空值,程序代碼如下:
下面給出junit測試時的錯誤語句
下面給出Junit運行時控制臺輸出的語句:
九月?26,?2014?9:31:33?上午?org.springframework.context.support.ClassPathXmlApplicationContext?prepareRefresh
INFO:?Refreshing?org.springframework.context.support.ClassPathXmlApplicationContext@5cba16:?startup?date?[Fri?Sep?26?09:31:33?CST?2014];?root?of?context?hierarchy
九月?26,?2014?9:31:33?上午?org.springframework.beans.factory.xml.XmlBeanDefinitionReader?loadBeanDefinitions
INFO:?Loading?XML?bean?definitions?from?class?path?resource?[applicationContext.xml]
九月?26,?2014?9:31:34?上午?org.springframework.context.support.PropertySourcesPlaceholderConfigurer?loadProperties
INFO:?Loading?properties?file?from?class?path?resource?[jdbc.properties]
九月?26,?2014?9:31:34?上午?org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor?
INFO:?JSR-330?""javax.inject.Inject""?annotation?found?and?supported?for?autowiring
九月?26,?2014?9:31:34?上午?com.mchange.v2.log.slf4j.Slf4jMLog$Slf4jMLogger$InfoLogger?log
INFO:?MLog?clients?using?slf4j?logging.
九月?26,?2014?9:31:34?上午?com.mchange.v2.log.slf4j.Slf4jMLog$Slf4jMLogger$InfoLogger?log
INFO:?Initializing?c3p0-0.9.5-pre8?[built?04-April-2014?04:20:15?-0700;?debug??true;?trace:?10]
九月?26,?2014?9:31:34?上午?org.hibernate.annotations.common.reflection.java.JavaReflectionManager?
INFO:?HCANN000001:?Hibernate?Commons?Annotations?{4.0.4.Final}
九月?26,?2014?9:31:34?上午?org.hibernate.Version?logVersion
INFO:?HHH000412:?Hibernate?Core?{4.3.5.Final}
九月?26,?2014?9:31:34?上午?org.hibernate.cfg.Environment?
INFO:?HHH000206:?hibernate.properties?not?found
九月?26,?2014?9:31:34?上午?org.hibernate.cfg.Environment?buildBytecodeProvider
INFO:?HHH000021:?Bytecode?provider?name?:?javassist
九月?26,?2014?9:31:34?上午?com.mchange.v2.log.slf4j.Slf4jMLog$Slf4jMLogger$InfoLogger?log
INFO:?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,?contextClassLoaderSource?->?caller,?dataSourceName?->?1hge137941cpv65mc0oevj|15fcabc,?debugUnreturnedConnectionStackTraces?->?false,?description?->?null,?driverClass?->?com.microsoft.sqlserver.jdbc.SQLServerDriver,?extensions?->?{},?factoryClassLocation?->?null,?forceIgnoreUnresolvedTransactions?->?false,?forceUseNamedDriverClass?->?false,?identityToken?->?1hge137941cpv65mc0oevj|15fcabc,?idleConnectionTestPeriod?->?60,?initialPoolSize?->?10,?jdbcUrl?->?jdbc:sqlserver://localhost:1433;DatabaseName=zl,?maxAdministrativeTaskTime?->?0,?maxConnectionAge?->?0,?maxIdleTime?->?60,?maxIdleTimeExcessConnections?->?0,?maxPoolSize?->?30,?maxStatements?->?200,?maxStatementsPerConnection?->?30,?minPoolSize?->?5,?numHelperThreads?->?3,?preferredTestQuery?->?null,?privilegeSpawnedThreads?->?false,?properties?->?{user=******,?password=******},?propertyCycle?->?0,?statementCacheNumDeferredCloseThreads?->?0,?testConnectionOnCheckin?->?false,?testConnectionOnCheckout?->?false,?unreturnedConnectionTimeout?->?0,?userOverrides?->?{},?usesTraditionalReflectiveProxies?->?false?]
九月?26,?2014?9:31:35?上午?org.hibernate.dialect.Dialect?
INFO:?HHH000400:?Using?dialect:?org.hibernate.dialect.SQLServer2008Dialect
九月?26,?2014?9:31:35?上午?org.hibernate.engine.transaction.internal.TransactionFactoryInitiator?initiateService
INFO:?HHH000399:?Using?default?transaction?strategy?(direct?JDBC?transactions)
九月?26,?2014?9:31:35?上午?org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory?
INFO:?HHH000397:?Using?ASTQueryTranslatorFactory
九月?26,?2014?9:31:35?上午?org.hibernate.validator.util.Version?
INFO:?Hibernate?Validator?bean-validator-3.0-JBoss-4.0.2
九月?26,?2014?9:31:35?上午?org.hibernate.tool.hbm2ddl.SchemaUpdate?execute
INFO:?HHH000228:?Running?hbm2ddl?schema?update
九月?26,?2014?9:31:35?上午?org.hibernate.tool.hbm2ddl.SchemaUpdate?execute
INFO:?HHH000102:?Fetching?database?metadata
九月?26,?2014?9:31:35?上午?org.hibernate.tool.hbm2ddl.SchemaUpdate?execute
INFO:?HHH000396:?Updating?schema
九月?26,?2014?9:31:35?上午?org.hibernate.tool.hbm2ddl.TableMetadata?
INFO:?HHH000261:?Table?found:?zl.dbo.t_user
九月?26,?2014?9:31:35?上午?org.hibernate.tool.hbm2ddl.TableMetadata?
INFO:?HHH000037:?Columns:?[id,?username,?allowance,?name,?basepay,?salary,?realname,?duties,?branchname,?password,?indexs]
九月?26,?2014?9:31:35?上午?org.hibernate.tool.hbm2ddl.TableMetadata?
INFO:?HHH000108:?Foreign?keys:?[]
九月?26,?2014?9:31:35?上午?org.hibernate.tool.hbm2ddl.TableMetadata?
INFO:?HHH000126:?Indexes:?[pk__t_user__3213e83f060deae8,?uk_g8gqk4e142wekcb1t6d3v2mwx]
九月?26,?2014?9:31:35?上午?org.hibernate.tool.hbm2ddl.SchemaUpdate?execute
INFO:?HHH000232:?Schema?update?complete
九月?26,?2014?9:31:36?上午?org.springframework.orm.hibernate4.HibernateTransactionManager?afterPropertiesSet
INFO:?Using?DataSource?[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,?contextClassLoaderSource?->?caller,?dataSourceName?->?1hge137941cpv65mc0oevj|15fcabc,?debugUnreturnedConnectionStackTraces?->?false,?description?->?null,?driverClass?->?com.microsoft.sqlserver.jdbc.SQLServerDriver,?extensions?->?{},?factoryClassLocation?->?null,?forceIgnoreUnresolvedTransactions?->?false,?forceUseNamedDriverClass?->?false,?identityToken?->?1hge137941cpv65mc0oevj|15fcabc,?idleConnectionTestPeriod?->?60,?initialPoolSize?->?10,?jdbcUrl?->?jdbc:sqlserver://localhost:1433;DatabaseName=zl,?maxAdministrativeTaskTime?->?0,?maxConnectionAge?->?0,?maxIdleTime?->?60,?maxIdleTimeExcessConnections?->?0,?maxPoolSize?->?30,?maxStatements?->?200,?maxStatementsPerConnection?->?30,?minPoolSize?->?5,?numHelperThreads?->?3,?preferredTestQuery?->?null,?privilegeSpawnedThreads?->?false,?properties?->?{user=******,?password=******},?propertyCycle?->?0,?statementCacheNumDeferredCloseThreads?->?0,?testConnectionOnCheckin?->?false,?testConnectionOnCheckout?->?false,?unreturnedConnectionTimeout?->?0,?userOverrides?->?{},?usesTraditionalReflectiveProxies?->?false?]]?of?Hibernate?SessionFactory?for?HibernateTransactionManager
但是,按照下面的邏輯順序來執(zhí)行時卻沒有發(fā)生錯誤:
action類調(diào)用manage類,manage類調(diào)用dao類,manage類和dao類的代碼不變。
下面給出action類的代碼:
我想請問一下,這是為什么?如何解決?請給出具體的代碼,先謝了!
總結(jié)
以上是生活随笔為你收集整理的junit可执行但控制层无法执行_Junit测试时ContextLoader.getCurrentWebApplicationContext()返回空值...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 折叠屏iPhone更近了:苹果新专利缓解
- 下一篇: 马斯克回应车主维权:涨价也没人给我补差价