林試圖導入兩個不同的罐中,主要項目的context.xml這樣當我們導入context.xml中兩個不同的罐子
<import resource="classpath*:/META-INF/mini-project-1-context.xml" />
<import resource="classpath*:/META-INF/mini-project-2-context.xml" />
它的失敗,小項目服務,回購協議自動連接自動連接失敗。每個迷你項目都有mysql配置。請找到我的項目結構。
main-project.war
|
------- main-project-context.xml
| |
| |
| mini-project-1.jar
| |
| ------- mini-project-1-context.xml
| |
| ------- persistence.xml
|
mini-project-2.jar
|
------- mini-project-2-context.xml
|
------- persistence.xml
find mini-project-1-context.xml。項目名稱只在另一context.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:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<context:component-scan
base-package="com.mini.project.one" />
<jpa:repositories base-package="com.mini.project.one.repo" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
depends-on="flyway">
<property name="persistenceXmlLocation"
value="classpath:/META-INF/persistence.xml" />
<property name="dataSource" ref="mini-1-DataSource" />
<property name="persistenceUnitName" value="Mini1PU" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
</props>
</property>
</bean>
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<jee:jndi-lookup jndi-name="project/DS/miniproject1"
resource-ref="true" id="mini-1-DataSource" />
<bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
<property name="dataSource" ref="mini-1-DataSource" />
<property name="table" value="module1_schema_version" />
<property name="initOnMigrate" value="false" />
<property name="locations" value="classpath:db/migration" />
</bean>
<!-- ************ JPA configuration *********** -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
主要項目的context.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:camel="http://camel.apache.org/schema/spring"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<context:component-scan base-package="com.main.project" />
<import resource="classpath*:/META-INF/mini-project-1-context.xml" />
<import resource="classpath*:/META-INF/mini-project-2-context.xml" />
<camelContext xmlns="http://camel.apache.org/schema/spring"
trace="true">
<contextScan />
</camelContext>
即時得到以下錯誤
12:03:33.894 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retrieved dependent beans for bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#1e5bc130': [entityManagerFactory]
12:03:33.894 [localhost-startStop-1] ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field:
得到改變
的pom.xml
<dependency>
<groupId>com.project</groupId>
<artifactId>mini-project-1</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.project</groupId>
<artifactId>mini-project-1</artifactId>
<version>1.0</version>
</dependency>
你是如何導出你的JAR的?如果你使用eclipse導出jar,你必須明確點擊'Add Directory Entries'選項。請參考http://stackoverflow.com/questions/13245570/jar-file-add-directory-entries-eclipse-option-while-exporting-jar – ArunM 2015-02-12 09:13:05
我通過maven依賴關係引用此jar。如果即時通訊添加一個罐子的意義上它的工作,但當我添加兩個罐子的maven依賴其失敗.. – Naveenkumar 2015-02-12 10:16:51
你可以請張貼在這裏爲你的主要戰爭pom – ArunM 2015-02-12 10:40:36