20

我正在尝试使用示例Struts 2 + Spring + Hibernate integration example来学习 Hibernate-Spring-Struts 。

但是在创建pom.xml得到这个错误之后:

Missing artifact javax.transaction:jta:jar:1.0.1B

我仅在创建pom.xml文件方面取得了进展,并进行了更改以包含最新的库。

这是我的pom.xml

<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>S3HMaven</groupId>
<artifactId>S3HMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>S3HMaven</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.0.1B</version>
    </dependency>

    <!-- Struts 2 -->
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.1.8</version>
    </dependency>

    <!-- Struts 2 + Spring plugins -->
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-spring-plugin</artifactId>
        <version>2.3.15.2</version>
    </dependency>

    <!-- MySQL database driver -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.26</version>
    </dependency>

    <!-- Spring framework -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <version>2.5.6</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>2.5.6</version>
    </dependency>

    <!-- Hibernate core -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>3.2.7.ga</version>
    </dependency>

    <!-- Hibernate core library dependency start -->
    <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>

    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>

    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2</version>
    </dependency>
    <!-- Hibernate core library dependency end -->

    <!-- Hibernate query library dependency start -->
    <dependency>
        <groupId>antlr</groupId>
        <artifactId>antlr</artifactId>
        <version>2.7.7</version>
    </dependency>
    <!-- Hibernate query library dependency end -->

</dependencies>
</project>

我尝试了依赖和不依赖javax.transation. 没有区别。谁能告诉我我做错了什么?我应该怎么做才能摆脱它?

4

6 回答 6

28

就我而言,我尝试了 mkyong 的示例

jsf-2.0 spring hibernate 集成示例

当我遇到异常时,我搜索了很多我正在使用 spring sts suit 工具,并使用 JDK 8 eclipse MARS解决方案是

我将 pom 更改为1.1而不是1.0.1B

<dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
</dependency>

如果它不能从 m2 repo 自动下载,你应该手动下载它(你可以在文件夹中的 repo 中检查它C:\Users\pc1\.m2\repository\javax\transaction\jta\1.1\jta-1.1.jar

并检查项目属性中的 maven 依赖项,它不应该在 lib 选项卡中给你一个错误。

参考: 参考1 参考2 参考3 参考4 参考5

如果您正在应用教程,则在解决此问题后可能会出现相关问题:

1- http://www.mkyong.com/web-development/the-web-xml-deployment-descriptor-examples/

2- http://jonathan.lalou.free.fr/?p=2026

3-创建名为“sessionFactory”的 bean 时出错 无法实例化默认 tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer] Tomcat 错误:在 ExternalContext 中找不到作为资源

于 2015-07-10T17:46:51.593 回答
8

你的错误是pom.xml因为你弄乱了不同版本的 Struts 核心和插件。

改变

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>2.3.15.2</version>
</dependency>

我不知道你为什么需要 JTA 1.0.1B 但你可以将休眠更改为 3.3.2(至少,没有头痛)

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate</artifactId>
    <version>3.3.2.ga</version>
</dependency>

它具有 JTA 1.1 的推荐依赖项。

创建一个新项目,pom.xml然后将源文件添加到其中。

于 2013-09-30T15:10:42.790 回答
6

您正在使用哪个存储库?

添加java.net Maven 存储库,如下所示。

<repository>
    <id>java.net</id>
    <url>http://download.java.net/maven/2/</url>
</repository>
于 2013-09-30T05:22:15.553 回答
2

这个回购对我有用:

   <repository>
           <id>webpublico-repository</id>
                <name>Webpublico Nexus Repository</name>
                <url>http://repository.webpublico.com.br/repository/maven-public/</url>
   </repository>
于 2017-08-16T02:32:03.827 回答
1

Unable to resolve javax.transaction 依赖的一些方法

清除 .ivy/cache 文件夹。它有效,但需要很长时间

于 2015-08-04T15:22:27.933 回答
0

目前,这可能是不必要的。但我认为我们应该为某人更新这张票。

这个对我有用。更改porm.xml

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>2.5.16</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.3.3.Final</version>
</dependency>
于 2018-08-02T03:14:16.293 回答