我有spring boot应用程序,我正试图从另一个jar加载应用程序上下文。这个jar有一些通用的方法,因此每个模块都会将该Jar导入到那些通用的方法中。我正在使用@ImportResource加载jar的上下文xml文件。
@ImportResource({"classpath:META-INF/spring/serviceApplicationContext.xml"})
serviceApplicationContext.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:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- The @AspectJ support is enabled by including the below tag -->
<aop:aspectj-autoproxy/>
<!-- Aspect -->
<bean id="loggingAspect" class="com.mellon.hris.hsa.aspect.LoggingAspect" />
<!--
The variable testDatasourceContextXmlSuffix is set in pom.xml as a
configuration of maven-surefire-plugin. So this variable will be set
when unit tests are run. ie
serviceApplicationContext_dataSources_test.xml will be loaded when
running maven test otherwise serviceApplicationContext_dataSources.xml
will be loaded.
-->
<context:property-placeholder location="classpath*:META-INF/spring/*.properties" />
<!-- <import resource="serviceApplicationContext_dataSources${testDatasourceContextXmlSuffix:}.xml" /> -->
<import resource="classpath*:META-INF/spring/applicationContext-common.xml" />
<import resource="classpath*:META-INF/spring/applicationContext-SoapWebservice.xml" />
<import resource="classpath*:META-INF/spring/serviceApplicationContext-SoapWebservice.xml" />
<bean id="applicationProperties" class="com.mellon.hris.hsa.util.PropertiesUtil">
<property name="locations">
<list>
<!-- <value>classpath:#{systemProperties['config.env'].toLowerCase()}/Location.properties</value>
<value>classpath:#{systemProperties['config.env'].toLowerCase()}/#{systemProperties['client.HPPCode']}Location.properties</value> -->
<value>classpath:test/Location.properties</value>
</list>
</property>
</bean>
<bean id="oracleDatasource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/hsawebsite</value>
</property>
<property name="resourceRef">
<value>false</value>
</property>
</bean>
<bean id="db2Datasource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/MFDB2</value>
</property>
<property name="resourceRef">
<value>false</value>
</property>
</bean>
<bean id="dsMETASCANDatasource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/dsMETASCAN1</value>
</property>
<property name="resourceRef">
<value>false</value>
</property>
</bean>
<!--
Turn on AspectJ @Configurable support. As a result, any time you
instantiate an object, Spring will attempt to perform dependency
injection on that object.
-->
<context:spring-configured />
<context:component-scan base-package="com.mellon.hris.hsa">
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation" />
</context:component-scan>
<tx:annotation-driven transaction-manager="oraTransactionManager" proxy-target-class="false"/>
<tx:annotation-driven transaction-manager="db2TransactionManager" proxy-target-class="false"/>
<!-- 1065-Employer Profile - Address update -Start -->
<!-- <tx:annotation-driven transaction-manager="oraEmsTransactionManager" proxy-target-class="false"/> -->
<!-- 1065-Employer Profile - Address update -End -->
<bean id="oraTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="oracleDatasource"/>
</bean>
<bean id="db2TransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="db2Datasource"/>
</bean>
<!-- 1065-Employer Profile - Address update -Start -->
<!-- <bean id="oraEmsTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> -->
<!-- <property name="dataSource" ref="oracleEMSDatasource"/> -->
<!-- </bean> -->
<!-- 1065-Employer Profile - Address update -End -->
<bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler"/>
<bean id="oraSqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:META-INF/ibatis/oraSqlMapConfig.xml</value>
</property>
<property name="dataSource" ref="oracleDatasource" />
<property name="lobHandler" ref="oracleLobHandler"></property>
</bean>
<bean id="db2SqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<!-- <value>classpath:META-INF/ibatis/db2SqlMapConfig.xml</value> -->
<value>classpath:META-INF/ibatis/#{systemProperties['client.HPPCode']}db2SqlMapConfig.xml</value>
</property>
<property name="dataSource" ref="db2Datasource" />
</bean>
<!-- 1065-Employer Profile - Address update -Start -->
<!-- <bean id="emsOraSqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:META-INF/ibatis/emsOraSqlMapConfig.xml</value>
</property>
<property name="dataSource" ref="oracleEMSDatasource" />
<property name="lobHandler" ref="oracleLobHandler"></property>
</bean> -->
<!-- 1065-Employer Profile - Address update -End -->
<bean class="com.mellon.hris.hsa.util.FlexPropertyConfigManager" factory-method="setStaticProperties" autowire="byName" scope="singleton">
<constructor-arg ref="commonService" />
</bean>
<bean class="org.springframework.mail.javamail.JavaMailSenderImpl"
id="mailSender">
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.host">${email.host}</prop>
<prop key="mail.smtp.port">${email.port}</prop>
<prop key="mail.smtp.username">${email.username}</prop>
<prop key="mail.smtp.password">${email.password}</prop>
<!-- Added timeout for SMTP servers as part of HSA_1392 -->
<prop key="mail.smtp.timeout">${email.timeout}</prop>
</props>
</property>
</bean>
<bean id="emailProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location"
value="classpath:META-INF/spring/email.properties" />
</bean>
<bean class="com.mellon.hris.hsa.util.EmailUtility" factory-method="setStaticProperties" autowire="byName" scope="singleton">
<constructor-arg ref="emailProperties" />
<constructor-arg ref="mailSender" />
<constructor-arg ref="commonService" />
</bean>
<bean class="com.mellon.hris.hsa.util.CacheRefreshHandler" factory-method="setStaticProperties" autowire="byName" scope="singleton">
<constructor-arg ref="accountService" />
</bean>
<bean class="com.mellon.hris.hsa.util.AuditHelper" factory-method="setStaticProperties" autowire="byName" scope="singleton">
<constructor-arg ref="commonService" />
</bean>
<bean id="log4jInitialization"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass"
value="org.springframework.util.Log4jConfigurer" />
<property name="targetMethod" value="initLogging" />
<property name="arguments">
<list>
<!-- <value>classpath:#{systemProperties['config.env'].toLowerCase()}/log4j.properties</value> -->
<value>classpath:test/log4j.properties</value>
</list>
</property>
</bean>
</beans>
当我尝试运行Spring Boot应用程序时,出现以下异常:
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ibatis.sqlmap.client.SqlMapClient com.mellon.hris.hsa.dao.impl.AccountDAOImpl.oraSqlMapClient; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oraSqlMapClient' defined in class path resource [META-INF/spring/serviceApplicationContext.xml]: Cannot resolve reference to bean 'oracleDatasource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oracleDatasource': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceInitializer': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
... 30 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oraSqlMapClient' defined in class path resource [META-INF/spring/serviceApplicationContext.xml]: Cannot resolve reference to bean 'oracleDatasource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oracleDatasource': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceInitializer': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
请帮助我,我在这个问题上陷入困境。