我有一个基于Swing、Spring 2.5.2、Hibernate 3.3.1的应用程序。
例如,如果我的应用程序从包含空格字符的目录运行
D:\hudson\jobs\FooBar - Fast Build
,然后我得到这个错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring-persistence.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: error trying to scan <jar-file>: file:/D:/hudson/jobs/FooBar%20-%20Fast%20Build/workspace/commons/target/classes/
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1302)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:463)
...
Caused by: java.lang.RuntimeException: error trying to scan <jar-file>: file:/D:/hudson/jobs/FooBar%20-%20Fast%20Build/workspace/commons/target/classes/
at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:635)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:350)
...
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: D:\hudson\jobs\FooBar%20-%20Fast%20Build\workspace\commons\target\classes (The system cannot find the path specified)
at org.jboss.util.file.JarArchiveBrowser.<init>(JarArchiveBrowser.java:74)
at org.jboss.util.file.FileProtocolArchiveBrowserFactory.create(FileProtocolArchiveBrowserFactory.java:48)
...
Caused by: java.io.FileNotFoundException: D:\hudson\jobs\FooBar%20-%20Fast%20Build\workspace\commons\target\classes (The system cannot find the path specified)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:114)
at java.util.jar.JarFile.<init>(JarFile.java:133)
at java.util.jar.JarFile.<init>(JarFile.java:97)
at org.jboss.util.file.JarArchiveBrowser.<init>(JarArchiveBrowser.java:69)
... 49 more
(请注意,在这种情况下,错误发生在由Hudson作业启动的单元测试期间)
如您所见,每个空格字符都被替换为
%20
在URL中,这可能是问题的根源…
您知道为什么会发生这种情况,以及如何解决它(当然,重新编写应用程序的整个路径将解决问题,但这不是我要寻找的答案);)吗?
附言:我不知道它是否能帮助你,但是豆子
entityManagerFactory
创建于
spring-persistence.xml
具有以下定义的文件:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="oraclePersistenceUnit"/>
<property name="dataSource" ref="dataSource"/>
</bean>
(特性在弹簧定义的另一个位置或
persistence.xml
文件)
在应用程序中运行以下代码时引发错误:
applicationContext = new ClassPathXmlApplicationContext("/my-spring-config.xml");
my-spring-config
位于
src/main/resources
我的申请目录。
我也用
FileSystemXmlApplicationContext
但是问题仍然存在。