我的问题恰恰是这样:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emf' defined in class path resource [main/resources/ApplicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/SystemException
我的pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>testbdd3</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>my-repo1</id>
<name>central repository</name>
<url>http://central.maven.org/maven2/</url>
</repository>
<repository>
<id>spring</id>
<name>spring depository</name>
<url>https://repo.spring.io/milestone/</url>
</repository>
</repositories>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<compilerArgs>
<arg>--add-opens java.base/java.lang=ALL-UNNAMED</arg>
</compilerArgs>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.0</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.0</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.0.RC1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.0.RC1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.1.0.RC1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.1.0.RC1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.1.0.RC1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.1.0.RC1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.1.0.RC1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.5.0</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180725.0427</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.4.Final</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.3.4.Final</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
我的依赖树
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building testbdd3 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ testbdd3 ---
[INFO] test:testbdd3:pom:1.0-SNAPSHOT
[INFO] +- com.h2database:h2:jar:1.4.197:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.11.0:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.11.0:compile
[INFO] +- org.springframework:spring-core:jar:5.1.0.RC1:compile
[INFO] | \- org.springframework:spring-jcl:jar:5.1.0.RC1:compile
[INFO] +- org.springframework:spring-context:jar:5.1.0.RC1:compile
[INFO] | \- org.springframework:spring-expression:jar:5.1.0.RC1:compile
[INFO] +- org.springframework:spring-orm:jar:5.1.0.RC1:compile
[INFO] | \- org.springframework:spring-jdbc:jar:5.1.0.RC1:compile
[INFO] +- org.springframework:spring-tx:jar:5.1.0.RC1:compile
[INFO] +- org.springframework:spring-aop:jar:5.1.0.RC1:compile
[INFO] +- org.springframework:spring-beans:jar:5.1.0.RC1:compile
[INFO] +- org.springframework.data:spring-data-jpa:jar:2.1.0.RC1:compile
[INFO] | +- org.springframework.data:spring-data-commons:jar:2.1.0.RC1:compile
[INFO] | +- org.aspectj:aspectjrt:jar:1.9.1:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- org.apache.commons:commons-dbcp2:jar:2.5.0:compile
[INFO] | \- org.apache.commons:commons-pool2:jar:2.6.0:compile
[INFO] +- javax.xml.bind:jaxb-api:jar:2.4.0-b180725.0427:compile
[INFO] | \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] +- org.hibernate:hibernate-core:jar:5.3.4.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] | +- org.javassist:javassist:jar:3.23.1-GA:compile
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.8.15:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile
[INFO] | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.1.1.Final:compile
[INFO] | +- org.jboss:jandex:jar:2.0.5.Final:compile
[INFO] | +- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.4.Final:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:5.3.4.Final:compile
[INFO] +- javax.persistence:javax.persistence-api:jar:2.2:compile
[INFO] \- javax.transaction:javax.transaction-api:jar:1.3:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total
time: 1.015 s
[INFO] Finished at: 2018-08-14T16:30:11+02:00
[INFO] Final Memory: 12M/54M
[INFO]
我试图运行一个运行data-jpa的应用程序以将数据存储到h2数据库中
我使用与spring- * 5.1.0.RC1兼容的spring-data 2.1.0.RC1
我拥有带有JDK-10.0.1的智能IDEA 2018.1
那么为什么javax / transaction / SystemException会丢失,即使它在依赖关系图中也以javax.transaction:javax.transaction-api:jar:1.3:compile和module-info出现
我的模块信息
open module testbdd3 {
requires spring.context;
requires spring.core;
requires spring.tx;
requires spring.data.jpa;
requires spring.aop;
requires spring.beans;
requires spring.data.commons;
requires spring.expression;
requires spring.jcl;
requires spring.jdbc;
requires spring.orm;
requires java.sql;
requires java.persistence;
requires org.hibernate.commons.annotations;
requires hibernate.entitymanager;
requires org.hibernate.orm.core;
requires java.activation;
requires java.transaction;
requires h2;
exports fr.certytech.print.bll;
}
我想我在模块信息中加入了很多内容,但是,当它起作用时,我会从中删除一些东西。
我的ApplicationContext.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:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.8.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:datasource.properties" />
</bean>
<context:annotation-config/>
<bean id="datasource" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${user}" />
<property name="password" value="${pass}" />
<property name="initialSize" value="2"/>
<property name="maxTotal" value="8"/>
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="packagesToScan">
<list>
<value>fr.testbdd.bo</value>
</list>
</property>
<property name="dataSource" ref="datasource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
</bean>
</property>
<property name="jpaProperties">
<props>
<!--<prop key="showSql">true</prop>-->
<prop key="generateDdl">create-drop</prop>
<!--<prop key="database">H2</prop>
<prop key="hibernate.format_sql">true</prop>-->
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emf"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<jpa:repositories
base-package="fr.testbdd.dao"
entity-manager-factory-ref="emf"
transaction-manager-ref="transactionManager"
/>
</beans>