java.io.FileNotFoundException: class path resource [WEB-INF/classes/cn/golaxy/yqpt/pojo/] cannot be resolved to URL because it

在做spring的集成测试时,运行JUnit Test报错:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name

'org.springframework.transaction.interceptor.TransactionInterceptor#0': Cannot resolve

reference to bean 'transactionManager' while setting bean property 'transactionManager';

nested exception is org.springframework.beans.factory.BeanCreationException: Error

creating bean with name 'transactionManager' defined in class path resource

[applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting

bean property 'sessionFactory'; nested exception is

org.springframework.beans.factory.BeanCreationException: Error creating bean with name

'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of

init method failed; nested exception is java.io.FileNotFoundException: class path resource

[WEB-INF/classes/cn/golaxy/yqpt/pojo/] cannot be resolved to URL because it does not exist
    at

org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference

(BeanDefinitionValueResolver.java:275)
    at

org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecess

ary(BeanDefinitionValueResolver.java:104)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyProperty

Values(AbstractAutowireCapableBeanFactory.java:1245)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean

(AbstractAutowireCapableBeanFactory.java:1010)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean

(AbstractAutowireCapableBeanFactory.java:472)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run

(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean

(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject

(AbstractBeanFactory.java:264)
    at

org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton

(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean

(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean

(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean

(AbstractBeanFactory.java:164)
    at

org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSinglet

ons(DefaultListableBeanFactory.java:429)
    at

org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitializa

tion(AbstractApplicationContext.java:729)
    at org.springframework.context.support.AbstractApplicationContext.refresh

(AbstractApplicationContext.java:381)
    at

org.springframework.test.AbstractSingleSpringContextTests.createApplicationContext

(AbstractSingleSpringContextTests.java:213)
    at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations

(AbstractSingleSpringContextTests.java:189)
    at org.springframework.test.AbstractSingleSpringContextTests.loadContext

(AbstractSingleSpringContextTests.java:169)
    at org.springframework.test.AbstractSpringContextTests.getContext

(AbstractSpringContextTests.java:140)
    at org.springframework.test.AbstractSingleSpringContextTests.setUp

(AbstractSingleSpringContextTests.java:98)
    at junit.framework.TestCase.runBare(TestCase.java:132)
    at org.springframework.test.ConditionalTestCase.runBare

(ConditionalTestCase.java:76)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:232)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run

(JUnit4TestReference.java:38)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests

(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests

(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run

(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main

(RemoteTestRunner.java:196)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean

with name 'transactionManager' defined in class path resource [applicationContext.xml]:

Cannot resolve reference to bean 'sessionFactory' while setting bean property

'sessionFactory'; nested exception is

org.springframework.beans.factory.BeanCreationException: Error creating bean with name

'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of

init method failed; nested exception is java.io.FileNotFoundException: class path resource

[WEB-INF/classes/cn/golaxy/yqpt/pojo/] cannot be resolved to URL because it does not exist
    at

org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference

(BeanDefinitionValueResolver.java:275)
    at

org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecess

ary(BeanDefinitionValueResolver.java:104)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyProperty

Values(AbstractAutowireCapableBeanFactory.java:1245)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean

(AbstractAutowireCapableBeanFactory.java:1010)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean

(AbstractAutowireCapableBeanFactory.java:472)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run

(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean

(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject

(AbstractBeanFactory.java:264)
    at

org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton

(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean

(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean

(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean

(AbstractBeanFactory.java:164)
    at

org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference

(BeanDefinitionValueResolver.java:269)
    ... 35 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean

with name 'sessionFactory' defined in class path resource [applicationContext.xml]:

Invocation of init method failed; nested exception is java.io.FileNotFoundException: class

path resource [WEB-INF/classes/cn/golaxy/yqpt/pojo/] cannot be resolved to URL because it

does not exist
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBea

n(AbstractAutowireCapableBeanFactory.java:1337)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean

(AbstractAutowireCapableBeanFactory.java:473)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run

(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean

(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject

(AbstractBeanFactory.java:264)
    at

org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton

(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean

(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean

(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean

(AbstractBeanFactory.java:164)
    at

org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference

(BeanDefinitionValueResolver.java:269)
    ... 48 more
Caused by: java.io.FileNotFoundException: class path resource [WEB-

INF/classes/cn/golaxy/yqpt/pojo/] cannot be resolved to URL because it does not exist
    at org.springframework.core.io.ClassPathResource.getURL

(ClassPathResource.java:162)
    at org.springframework.core.io.ClassPathResource.getFile

(ClassPathResource.java:174)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory

(LocalSessionFactoryBean.java:660)
    at

org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet

(AbstractSessionFactoryBean.java:211)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMet

hods(AbstractAutowireCapableBeanFactory.java:1368)
    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBea

n(AbstractAutowireCapableBeanFactory.java:1334)
    ... 58 more

 

解决方法:

修改spring的配置文件applicationContext.xml中的:


      
            /WEB-INF/classes/cn/golaxy/yqpt/pojo/
      

为:


      
           classpath:cn/golaxy/yqpt/pojo/
      


 

你可能感兴趣的:(Spring)