<!-- ============== Second================== -->
<bean id="secondDataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="net.sourceforge.jtds.jdbc.Driver">
</property>
<property name="url"
value="jdbc:jtds:sqlserver://192.168.10.230:1433;DatabaseName=regsys">
</property>
<property name="username" value="sa"></property>
<property name="password" value="1"></property>
</bean>
<bean id="SecondSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="secondDataSource" ref="secondDataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
</list>
</property>
</bean>

<bean id="myTranAttri"
class="org.springframework.transaction.interceptor.DefaultTransactionAttribute">
<property name="propagationBehaviorName">
<value>PROPAGATION_REQUIRED</value>
</property>
</bean> <bean id="myTransactionAttributeSource"
class="org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource">
<property name="transactionAttribute" ref="myTranAttri"></property>
</bean> <bean id="myTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="SecondSessionFactory"></property>
</bean> <bean id="txInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor"
lazy-init="true">
<property name="transactionManager" ref="myTransactionManager"></property>
<property name="transactionAttributeSource" ref="myTransactionAttributeSource"></property>
</bean>
<!-- ============== First  ================== -->
<import resource="applicationContext-in.xml" /> <bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:init.properties</value>
</property>
</bean>
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close" dependency-check="none">
<property name="driverClass">
<value>${datasource.driverClassName}</value>
</property>
<property name="jdbcUrl">
<value>${datasource.url}</value>
</property>
<property name="user">
<value>${datasource.username}</value>
</property>
<property name="password">
<value>${datasource.password}</value>
</property>
<property name="acquireIncrement">
<value>${c3p0.acquireIncrement}</value>
</property>
<property name="initialPoolSize">
<value>${c3p0.initialPoolSize}</value>
</property>
<property name="minPoolSize">
<value>${c3p0.minPoolSize}</value>
</property>
<property name="maxPoolSize">
<value>${c3p0.maxPoolSize}</value>
</property>
<property name="maxIdleTime">
<value>${c3p0.maxIdleTime}</value>
</property>
<property name="idleConnectionTestPeriod">
<value>${c3p0.idleConnectionTestPeriod}</value>
</property>
<property name="maxStatements">
<value>${c3p0.maxStatements}</value>
</property>
<property name="numHelperThreads">
<value>${c3p0.numHelperThreads}</value>
</property>
</bean>

<bean id="SpringSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
</list>
</property>
</bean> <bean id="TransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="SpringSessionFactory"></property>
</bean>
<bean id="Proxy" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="TransactionManager"></property>
<property name="transactionAttributes">
<props>
<prop key="tran*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

解决方案 »

  1.   

    出错啊?该!往这贴一堆的 XML 就让人看错?
      

  2.   

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SecondSessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'secondDataSource' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'secondDataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    Caused by: 
    org.springframework.beans.NotWritablePropertyException: Invalid property 'secondDataSource' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'secondDataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?出错信息,我使用的是spring2.0+hibernate3.0+struts1.2
      

  3.   

    Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SecondSessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'secondDataSource' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'secondDataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    Caused by: 
    org.springframework.beans.NotWritablePropertyException: Invalid property 'secondDataSource' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'secondDataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:793)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:645)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1127)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:424)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    at org.springframework.web.struts.ContextLoaderPlugIn.createWebApplicationContext(ContextLoaderPlugIn.java:355)
    at org.springframework.web.struts.ContextLoaderPlugIn.initWebApplicationContext(ContextLoaderPlugIn.java:296)
    at org.springframework.web.struts.ContextLoaderPlugIn.init(ContextLoaderPlugIn.java:225)
    at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:1158)
    at org.apache.struts.action.ActionServlet.init(ActionServlet.java:473)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4149)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4458)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:556)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:491)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    2010-3-1 14:44:05 org.apache.catalina.core.ApplicationContext log
    严重: action: null全部出错信息
      

  4.   

    我是想连接2个数据库,按照网上的例子,就多写一个DataSource 和SessionFactory 出错提示,没有DataSource 和SessionFactory 属性
      

  5.   

    <bean id="SecondSessionFactory" 
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
    <property name="secondDataSource" ref="secondDataSource"> </property> 
    <property name="hibernateProperties"> 
    <props> 
    <prop key="hibernate.dialect"> 
    org.hibernate.dialect.SQLServerDialect 
    </prop> 
    <prop key="show_sql">true </prop> 
    </props> 
    </property> 
    <property name="mappingResources"> 
    <list> 
    </list> 
    </property> 
    </bean> 这里的property name 怎么会是secondDataSource的??
      

  6.   

    <property name="secondDataSource" ref="secondDataSource"></property>
    name写错了