精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2004-11-23
<property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> 在web application中能方便的找到web-inf/classes下的hibernate.cfg.xml. 当我用RCP来构建应用程序(结合了spring+hibernate)时,运行时却找不到hibernate.cfg.xml文件(这个文件放在Eclipse创建项目时自定义的classpath中,即 example/bin). 并显示如下错误: Caused by: java.io.FileNotFoundException: class path resource [hibernate.cfg.xml] cannot be resolved to URL because it does not exist at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:101); at org.springframework.orm.hibernate.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:347); at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:991); at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:288); 这是什么原因啊?ApplicatonContext.xml还能通过其他方式获得hibernate.cfg.xml的路径呢? 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2004-11-23
用的是LocalSessionFactoryBean?
看 afterPropertiesSet 还有 mappingDirectoryLocations和 mappingJarLocations |
|
返回顶楼 | |
发表时间:2004-11-23
jjx 写道 用的是LocalSessionFactoryBean?
用的是LocalSessionFactoryBean
看 afterPropertiesSet 还有 mappingDirectoryLocations和 mappingJarLocations |
|
返回顶楼 | |
发表时间:2004-11-23
引用 当我用RCP来构建应用程序(结合了spring+hibernate)时,运行时却找不到hibernate.cfg.xml文件(这个文件放在Eclipse创建项目时自定义的classpath中,即 example/bin). bin是eclipse的编译目录, 会被自动清除的, 你应该把这个文件放在src目录下面, 它会被自动copy过去的. |
|
返回顶楼 | |
发表时间:2004-11-23
谢谢你的回复。我将hibernate.cfg.xml放到src中了,bin中的文件也是从src中自动copy过去的。还是找不到这个文件。在ApplicationContext.xml我也是像第一帖中那样的定义:
classpath:hibernate.cfg.xml.我的不是web应用程序,由于做的事C/S中的C部分,所以无法在web.xml中加载applicationContext.xml.我是这样加载ApplicationContext.xml文件的: ctx = new AlternateClassPathXmlApplicationContext("applicationContext.xml", Messages.class);; [color=green]//加载配置文件[/color]然后当我通过含有main方法的swt的类文件中这样的调用: private static StationManager dgr = null; dgr = (StationManager); ctx.getBean("stationManager");; List ss = dgr.findAll();;运行时却显示如第一帖中的错误. |
|
返回顶楼 | |
发表时间:2004-11-23
试试看:
classpath:/hibernate.cfg.xml |
|
返回顶楼 | |
发表时间:2004-11-23
谢谢你的回复,这样改后,含main方法的类运行正常!!!
但是,我在另外一个类Formview.java有相同的定义.(一个SWT文件,不含main方法)并且我在plugin.xml文件中添加: <extension point="org.eclipse.ui.views"> <category name="Google" id="com.jctx.trms.views"/> <view class="com.jctx.trms.views.FormView" category="com.jctx.trms.views" name="FormView" id="com.jctx.trms.view.FormView"/> </extension> 然后构建RCP应用程序.运行,在生成的窗口中,点击窗口---显示视图---其他---Google--Form时,出现错误!!显示找不到hibernat.cfg.xml中所定义的*.hbm.xml文件了. 错误如下: Caused by: net.sf.hibernate.MappingException: Resource: com/jctx/trms/hibernate/persistence/DictItem.hbm.xml not found at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:334); at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1013); at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:969); at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:912); at org.springframework.orm.hibernate.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:347); at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:991); at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:288); |
|
返回顶楼 | |
发表时间:2004-11-23
sorry ,没看清楚你是指configLocation
按你的写法,理论上没有错,如果hibernate.cfg.xml在src下的话,我随手写了个swt 试了一下,正常。看来可能是其他问题 另外也可以将hibernate.cfg.xml的内容都写在applicationcontext.xml中啊 spring一般用DefaultResourceLoader来读取文件,不妨用这个看看 |
|
返回顶楼 | |
发表时间:2004-11-23
回去看文档, 理解了classpath的相对路径和绝对路径应该怎么写, 就能解决你的问题了.
|
|
返回顶楼 | |
发表时间:2004-11-23
引用 另外也可以将hibernate.cfg.xml的内容都写在applicationcontext.xml中啊
我也这样的写过,也出现错误:找不到*.hbm.xml文件(在用RCP构建应用程序运行时)。 谢谢两位的回复!!! |
|
返回顶楼 | |