繁体   English   中英

删除数据源连接Spring + JPA

[英]Removing Data Source Connection Spring + JPA

大家好,我在这里工作时遇到一个问题,初始化后有一个项目可以使用1个SQL Server实例,2个DB2实例。

问题是,该项目基于另一个项目来保持类似的结构,但是在这个新项目上,我们不使用在某些xml文件中引用的SQL Server实例,因此在启动时我试图注释这些引用在Tomcat上的项目,该项目向我展示了一些错误。

作为Spring的新功能,如何正确删除此连接?

beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jaxws="http://cxf.apache.org/jaxws" 
       xmlns:context="http://www.springframework.org/schema/context" 
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd          
       http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd         
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd         
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">

    <jee:jndi-lookup id="IP_ICMS_RJ" jndi-name="java:comp/env/IP_ICMS_RJ" />
    <jee:jndi-lookup id="USUARIO_ICMS_RJ" jndi-name="java:comp/env/USUARIO_ICMS_RJ" />
    <jee:jndi-lookup id="SENHA_ICMS_RJ" jndi-name="java:comp/env/SENHA_ICMS_RJ" />
    <jee:jndi-lookup id="IP_ICMS_SP" jndi-name="java:comp/env/IP_ICMS_SP" />
    <jee:jndi-lookup id="USUARIO_ICMS_SP" jndi-name="java:comp/env/USUARIO_ICMS_SP" />
    <jee:jndi-lookup id="SENHA_ICMS_SP" jndi-name="java:comp/env/SENHA_ICMS_SP" />

    <jee:jndi-lookup id="PSACWSDocumentURL" jndi-name="java:comp/env/PSACWSDocumentURL" />
    <jee:jndi-lookup id="PSACWSEndPoint" jndi-name="java:comp/env/PSACWSEndPoint" />

    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

    <aop:aspectj-autoproxy/>

    <bean id="FaleConoscoWSBean" class="br.com.embratel.faleconosco.ws.FaleConoscoWSBean">
    </bean>

    <bean id="RoboFaleConoscoWSBean" class="br.com.embratel.faleconosco.ws.RoboFaleConoscoWSBean">
    </bean>

    <!-- <bean id="faleConoscoDS" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/FaleConoscoDS" />
    </bean> -->

    <bean id="icmsRJDS" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/ICMS_RJ_DS" />
    </bean>

    <bean id="icmsSPDS" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/ICMS_SP_DS" />
    </bean>

    <bean id="icmsRJ" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
        <constructor-arg ref="icmsRJDS" />
    </bean>

    <bean id="icmsSP" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
        <constructor-arg ref="icmsSPDS" />
    </bean>

    <util:map id="icmsPropertiesMap">
        <entry key="IP_RJ" value-ref="IP_ICMS_RJ" />
        <entry key="USUARIO_RJ" value-ref="USUARIO_ICMS_RJ" />
        <entry key="SENHA_RJ" value-ref="SENHA_ICMS_RJ" />
        <entry key="IP_SP" value-ref="IP_ICMS_SP" />
        <entry key="USUARIO_SP" value-ref="USUARIO_ICMS_SP" />
        <entry key="SENHA_SP" value-ref="SENHA_ICMS_SP" />
    </util:map>

    <!-- Lista de processadores de OS -->    
    <util:list id="processors">
        <bean class="br.com.embratel.faleconosco.ws.service.os.processor.ClienteProcessor" />
        <bean class="br.com.embratel.faleconosco.ws.service.os.processor.ServicoEquipamentoProcessor" />
        <bean class="br.com.embratel.faleconosco.ws.service.os.processor.SuspensaoProcessor" />
        <bean class="br.com.embratel.faleconosco.ws.service.os.processor.SaldoProcessor" />
        <bean class="br.com.embratel.faleconosco.ws.service.os.processor.DebitoAutomaticoProcessor" />
    </util:list>

    <context:annotation-config />

    <context:component-scan base-package="br.com.embratel.faleconosco">
        <context:include-filter type="annotation" expression="javax.jws.WebService" />
    </context:component-scan>
    <!-- <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
         <property name="dataSource" ref="faleConoscoDS" /> 
        <property name="jpaDialect">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
        </property>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="database" value="SQL_SERVER" />
                 <property name="databasePlatform" value="org.hibernate.dialect.SQLServerDialect" />
                <property name="showSql" value="true" />
                <property name="generateDdl" value="false" />
            </bean>
        </property>
        <property name="jpaPropertyMap">
            <map>
                <entry key="org.hibernate.type" value="true" />
                <entry key="org.hibernate.transaction" value="true" />
            </map>
        </property>
    </bean>

    <bean id="jpaTemplate" class="br.com.embratel.faleconosco.ws.dao.JpaTemplateExt">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

      enable the configuration of transactional behavior based on annotations 
    <tx:annotation-driven transaction-manager="transactionManager" /> --> 

    <bean id="ProtocoloWS" class="org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean" scope="prototype">
        <property name="serviceFactoryClass">
            <value>org.apache.axis.client.ServiceFactory</value>
        </property>
        <property name="wsdlDocumentUrl" ref="PSACWSDocumentURL" />
        <property name="endpointAddress" ref="PSACWSEndPoint" />
        <property name="serviceName">
            <value>ProtocoloWSService</value>
        </property>
        <property name="namespaceUri">
            <value>http://webservices.protocolounico.embratel.com.br/</value>
        </property>
        <property name="portName">
            <value>ProtocoloWSPort</value>
        </property>
        <property name="portInterface">
            <value>br.com.embratel.protocolounico.webservices.ProtocoloWS</value>
        </property>   
        <property name="serviceInterface">
            <value>br.com.embratel.protocolounico.webservices.ProtocoloWS</value>
        </property>
        <property name="customPropertyMap">
            <map>
                <entry>
                    <key><value type="java.lang.String">axis.connection.timeout</value></key>
                    <value type="java.lang.Integer">300000</value>
                </entry>
            </map>
        </property>
    </bean>

    <bean id="LoggerAspect" class="br.com.embratel.faleconosco.ws.aop.LoggerAspect">
    </bean>

    <jaxws:endpoint xmlns:tns="http://ws.faleconosco.embratel.com.br/" id="faleconoscowsbean"
        implementor="#FaleConoscoWSBean" wsdlLocation="wsdl/faleconoscowsbean.wsdl" endpointName="tns:FaleConoscoWSPort"
        serviceName="tns:FaleConoscoWSService" address="/FaleConoscoWSPort">
        <jaxws:features>
            bean class="org.apache.cxf.feature.LoggingFeature" /
        </jaxws:features>
    </jaxws:endpoint> 

    <jaxws:endpoint xmlns:tns="http://ws.faleconosco.embratel.com.br/" id="robofaleconoscowsbean"
        implementor="#RoboFaleConoscoWSBean" wsdlLocation="wsdl/robofaleconoscowsbean.wsdl"
        endpointName="tns:RoboFaleConoscoWSPort" serviceName="tns:RoboFaleConoscoWSService" address="/RoboFaleConoscoWSPort">
        <jaxws:features>
            bean class="org.apache.cxf.feature.LoggingFeature" /
        </jaxws:features>
    </jaxws:endpoint>
</beans>

错误

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FaleConoscoWSBean': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.embratel.faleconosco.ws.service.usuario.UsuarioService br.com.embratel.faleconosco.ws.FaleConoscoWSBean.usuarioService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usuarioServiceImpl': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.embratel.faleconosco.ws.service.email.EnviarEmailService br.com.embratel.faleconosco.ws.service.usuario.UsuarioServiceImpl.enviarEmailService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enviarEmailServiceImpl': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.embratel.faleconosco.ws.dao.JpaTemplateExt br.com.embratel.faleconosco.ws.service.BaseServiceImpl.jpaTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [br.com.embratel.faleconosco.ws.dao.JpaTemplateExt] is defined: Unsatisfied dependency of type [class br.com.embratel.faleconosco.ws.dao.JpaTemplateExt]: expected at least 1 matching bean
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:243)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:959)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
    at 

好吧,我研究了更好的Spring并重新创建了xml。

我从上面的代码中删除了这部分代码。 从头开始创建文件。

<property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="database" value="SQL_SERVER" />
             <property name="databasePlatform" value="org.hibernate.dialect.SQLServerDialect" />
            <property name="showSql" value="true" />
            <property name="generateDdl" value="false" />
        </bean>
    </property>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM