读书人

讨论:Eclipse+Spring+Hibernate配置中

发布时间: 2012-01-08 22:48:50 作者: rapoo

讨论:Eclipse+Spring+Hibernate配置中的路径问题(分不够开新贴给分)
小第刚开始搞Spring,在Eclipse环境下开发。

/WEB-INF/web.xml配置

<display-name> ims </display-name>
<context-param>
<param-name> contextConfigLocation </param-name>
<param-value> /WEB-INF/applicationContext.xml </param-value>
</context-param>
<context-param>
<param-name> log4jConfigLocation </param-name>
<param-value> /WEB-INF/log4j.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>

在/WEB-INF/applicationContext.xml配置如下
<bean id= "propertyConfigurer " class= "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ">
<property name= "location " value= "/WEB-INF/jdbc.properties " />
</bean>

<bean id= "dataSource "
class= "org.springframework.jdbc.datasource.DriverManagerDataSource ">
<property name= "driverClassName " value= "${jdbc.driverClassName} " />
<property name= "url " value= "${jdbc.url} " />
<property name= "username " value= "${jdbc.username} " />
<property name= "password " value= "${jdbc.password} " />
</bean>

<!-- JNDI DataSource for J2EE environments -->
<!--
<bean id= "dataSource " class= "org.springframework.jndi.JndiObjectFactoryBean ">
<property name= "jndiName " value= "java:comp/env/jdbc/petclinic "/>
</bean>
-->

<!-- Hibernate SessionFactory -->
<bean id= "sessionFactory "
class= "org.springframework.orm.hibernate3.LocalSessionFactoryBean ">
<property name= "dataSource " ref= "dataSource " />
<property name= "mappingResources ">
<value> hibernate-mapping.hbm.xml </value>
</property>
<property name= "hibernateProperties ">
<props>
<prop key= "hibernate.dialect "> ${hibernate.dialect} </prop>
<prop key= "hibernate.show_sql "> true </prop>
<prop key= "hibernate.generate_statistics "> true </prop>
<prop key= "hibernate.hbm2ddl.auto "> update </prop>
</props>
</property>
<property name= "eventListeners ">
<map>
<entry key= "merge ">
<bean class= "org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener " />
</entry>
</map>
</property>
</bean>

以上代码在不同的应用服务器报的错也不一样,感觉就是hibernate-mapping.hbm.xml、jdbc.properties和applicationContext.xml的路径上出了问题。

请教:在eclipose开发web应用程序时,classpath到底是怎么回事呀?!如果提问不清楚,我再解释。

------解决方案--------------------


不如用myeclipse
不用配置多少东西
[解决办法]
Eclipse的配置文件默认放在项目的根目录下
[解决办法]
<property name= "mappingResources ">
<value> hibernate-mapping.hbm.xml </value>
</property
你的hibernate-mapping.hbm.xml放在哪里?
[解决办法]
classpath 感觉就是在环境变量里配置的路径。你可以将需要的jar文件放入 工程的lib文件夹下,然后将jar 导入工程立。 楼上说的 <value> hibernate-mapping.hbm.xml </value>
需要些文件的相对路径。比如 文件在 src/bean/hibernate-mapping.hbm.xml 你需要写
<value> bean\hibernate-mapping.hbm.xml </value>
不知道你的 错误是什么具体情况。
[解决办法]
其他配置文件放到 web-inf下就行,感觉你也应该是这么配置的。想知道在tomcat下报什么错误。
[解决办法]
up
[解决办法]
呵呵
[解决办法]
jf
[解决办法]
我自己写了个struts+spring+hibernate 的简单程序,有需要的话你短信我

读书人网 >Java Web开发

热点推荐