关于C/S结构中使用sping+hibernate 最近用eclipse开发一个项目,用的是swing + spring + hibernate,在eclipse在测试一切正常,但打包后就无法使用,测试后发现是无法连接到数据库,应该是spring中的路径不对,sping中是读取的外部的properties文件,谁知道该如何配置啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 spring配置文件如下:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans> <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>/dataSource1.properties</value> <value>/dataSource2.properties</value> </list> </property> </bean> <!-- 集成hibernate --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName"> <value>${datasource.driverClassName}</value> </property> <property name="url"> <value>jdbc:mysql://${datasource.host}:3306/${datasource.database}</value> </property> <property name="username"> <value>${datasource.username}</value> </property> <property name="password"> <value>${datasource.password}</value> </property> <property name="maxActive"> <value>${datasource.maxActive}</value> </property> <property name="maxIdle"> <value>${datasource.maxIdle}</value> </property> <property name="maxWait"> <value>${datasource.maxWait}</value> </property> <property name="defaultAutoCommit"> <value>${datasource.defaultAutoCommit}</value> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref local="dataSource" /> </property> <property name="mappingResources"> <list> <value>com/customer/bean/Customerinfo.hbm.xml</value> <value>com/customer/bean/Messageinfo.hbm.xml</value> <value>com/customer/bean/Userinfo.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> ${hibernate.dialect} </prop> <prop key="hibernate.show_sql"> ${hibernate.show_sql} </prop> <prop key="hibernate.jdbc.fetch_size"> ${hibernate.jdbc.fetch_size} </prop> <prop key="hibernate.jdbc.batch_size"> ${hibernate.jdbc.batch_size} </prop> </props> </property> </bean> <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation"> <value>classpath:com/customer/common/hibernate.cfg.xml</value> </property> </bean> --> <!-- 声明式事务 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!-- 事务规则 --> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="transactionManager" /> <property name="transactionAttributes"> <props> <prop key="add*">PROPAGATION_REQUIRED</prop> <prop key="del*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> <!-- 拦截器 --> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <value>*Service,*dao</value> </property> <property name="interceptorNames"> <list> <value>transactionInterceptor</value> <!-- 增加新的 Interceptor --> </list> </property> </bean> <bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"> <property name="transactionInterceptor" ref="transactionInterceptor" /> </bean> <!-- dao --> <bean id="userdao" class="com.customer.dao.impl.UserInfoDaoimpl" autowire="byName" /> <bean id="customerdao" class="com.customer.dao.impl.CustomerDaoImpl" autowire="byName" /> <bean id="messagedao" class="com.customer.dao.impl.MessageInfoDaoImpl" autowire="byName" /> <!-- service --> <bean id="userService" class="com.customer.service.impl.UserServiceImpl"> <property name="userdao"> <ref local="userdao" /> </property> </bean> <bean id="customerService" class="com.customer.service.impl.CustomerServiceImpl"> <property name="customerdao"> <ref local="customerdao" /> </property> </bean> <bean id="messageService" class="com.customer.service.impl.MessageServiceImpl"> <property name="messageInfoDao"> <ref local="messagedao" /> </property> </bean></beans> 如何读取的文件?property文件是放在哪里的使用类路径方式读取应该不会有问题 property文件放在jar包同一个目录下读取bean是用ApplicationContext apc = new ClassPathXmlApplicationContext("applicationContext.xml"); swing list接口? 关于output问题(初学者) 请问一个关于图片编码传输的问题(高分求解) 关于打包成.jar文件并运行的奇怪问题! 如何让jspinner只输入正数 寻找rational Rose下载地址 请帮我看看这小段代码,为什么不能在循环中执行sql? 很久没有用java了,不知道新出的jdk1.4在性能上是不是比以前的版本有明显的提高? 为什么我安装的JDK1.2中没有DOC目录 ,也没有公开的原程序那个目录。 读文件的问题,菜鸟在线等,急! SIPServlet中的doInvite()方法与文件传输
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans>
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/dataSource1.properties</value>
<value>/dataSource2.properties</value>
</list>
</property>
</bean> <!-- 集成hibernate -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>${datasource.driverClassName}</value>
</property>
<property name="url">
<value>jdbc:mysql://${datasource.host}:3306/${datasource.database}</value>
</property>
<property name="username">
<value>${datasource.username}</value>
</property>
<property name="password">
<value>${datasource.password}</value>
</property>
<property name="maxActive">
<value>${datasource.maxActive}</value>
</property>
<property name="maxIdle">
<value>${datasource.maxIdle}</value>
</property>
<property name="maxWait">
<value>${datasource.maxWait}</value>
</property>
<property name="defaultAutoCommit">
<value>${datasource.defaultAutoCommit}</value>
</property>
</bean> <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>com/customer/bean/Customerinfo.hbm.xml</value>
<value>com/customer/bean/Messageinfo.hbm.xml</value>
<value>com/customer/bean/Userinfo.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<prop key="hibernate.jdbc.fetch_size">
${hibernate.jdbc.fetch_size}
</prop>
<prop key="hibernate.jdbc.batch_size">
${hibernate.jdbc.batch_size}
</prop>
</props>
</property>
</bean> <!--
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:com/customer/common/hibernate.cfg.xml</value>
</property>
</bean>
--> <!-- 声明式事务 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean> <!-- 事务规则 -->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean> <!-- 拦截器 -->
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*Service,*dao</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
<!--
增加新的 Interceptor
-->
</list>
</property>
</bean> <bean
class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor"
ref="transactionInterceptor" />
</bean>
<!-- dao -->
<bean id="userdao" class="com.customer.dao.impl.UserInfoDaoimpl"
autowire="byName" /> <bean id="customerdao" class="com.customer.dao.impl.CustomerDaoImpl"
autowire="byName" /> <bean id="messagedao"
class="com.customer.dao.impl.MessageInfoDaoImpl" autowire="byName" /> <!-- service -->
<bean id="userService"
class="com.customer.service.impl.UserServiceImpl">
<property name="userdao">
<ref local="userdao" />
</property>
</bean> <bean id="customerService"
class="com.customer.service.impl.CustomerServiceImpl">
<property name="customerdao">
<ref local="customerdao" />
</property>
</bean> <bean id="messageService"
class="com.customer.service.impl.MessageServiceImpl">
<property name="messageInfoDao">
<ref local="messagedao" />
</property>
</bean>
</beans>
property文件是放在哪里的
使用类路径方式读取应该不会有问题
读取bean是用ApplicationContext apc = new ClassPathXmlApplicationContext("applicationContext.xml");