Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在context.xml中导入两个不同的jar时,自动连线失败_Java_Mysql_Xml_Spring_Spring Mvc - Fatal编程技术网

Java 在context.xml中导入两个不同的jar时,自动连线失败

Java 在context.xml中导入两个不同的jar时,自动连线失败,java,mysql,xml,spring,spring-mvc,Java,Mysql,Xml,Spring,Spring Mvc,Im尝试像这样在main project context.xml中导入两个不同的jar <import resource="classpath*:/META-INF/mini-project-1-context.xml" /> <import resource="classpath*:/META-INF/mini-project-2-context.xml" /> <?xml version="1.0" encoding="UTF-8"?><beans

Im尝试像这样在main project context.xml中导入两个不同的jar

<import resource="classpath*:/META-INF/mini-project-1-context.xml" />
<import resource="classpath*:/META-INF/mini-project-2-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>
查找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" />
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>

通过在依赖模块的context.xml中定义transactionManager和注释驱动(此处为main-project-context.xml),并从jar项目mini-project-1-context.xml和mini-project-2-context.xml中删除transactionManager,可以解决此问题

因此,从mini-project-1-context.xml和mini-project-2-context.xml中删除transactionManager和注释驱动


你是如何出口你的罐子的?如果使用eclipse导出jar,则必须明确单击“添加目录条目”选项。请参考我是通过maven依赖关系来参考这个jar的。如果我添加了一个jar,在某种意义上说它可以工作,但是当我同时添加两个jar时,它的依赖性就失败了。你能把pom贴在这里吗
 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:
<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>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
     <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<tx:annotation-driven />

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

<bean id="transactionManager1" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory1" />
    <qualifier value="qualifier1" />
</bean>