【问题标题】:Getting the error of The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'得到匹配通配符的错误是严格的,但是找不到元素'tx:annotation-driven'的声明
【发布时间】:2021-08-10 11:01:04
【问题描述】:

我正在学习 spring 框架,因此在使用 maven web 创建一个 spring 项目以连接视图和 mysql 工作台时。我创建了一个 xml 文件来配置我下载的依赖项 1.弹簧形式 2. 春天TX 3.mysql连接器 4.c3p0 5. 休眠核心。

下面是pom.xml文件

                                  pom.xml file


     <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/maven- 
    v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.amit</groupId>
     <artifactId>SpringMVCWithoutBoot</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>SpringMVCWithoutBoot Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    
      <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
     <dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-webmvc</artifactId>
     <version>5.1.4.RELEASE</version>
     </dependency>

      <!-- https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-core -->
       <dependency>
    <groupId>org.hibernate.orm</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>6.0.0.Alpha6</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>5.1.4.RELEASE</version>
    </dependency>

   <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>5.1.4.RELEASE</version>
    </dependency>

     <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
     <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.13</version>
     </dependency>

    <!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
    <dependency>
    <groupId>com.mchange</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.5.5</version>
    </dependency>


    </dependencies>
     <build>
    <finalName>SpringMVCWithoutBoot</finalName>
    </build>
   </project>

现在在 Servlet.xml 文件中,我在事务注释上遇到错误,即

        Amit-Servlet.xml

enter code here
 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:ctx="http://www.springframework.org/schema/context"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/mvc/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<ctx:component-scan base-package="com.SpringMVCWithoutBoot"></ctx:component-scan>
<ctx:annotation-config></ctx:annotation-config>


<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.cj.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/AmitDb"></property>
<property name="user" value="root"></property>
<property name="password" value="root"></property>

<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="10" />
<property name="maxIdleTime" value="30000" />
</bean>


<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="packageToScan" value="com.example.springmvcwithoutboot.model" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>  
</bean>



<bean id="myTransactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:annotation-driven transaction-manager="myTransactionManager" />


<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/view/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>

</beans>

【问题讨论】:

    标签: java spring maven spring-mvc model-view-controller


    【解决方案1】:

    【讨论】:

    • 注意,根据 StackOverflow 的规则,链接不是答案的一部分。所以你的答案归结为“而不是 mvc 尝试使用 tx”。您可能需要稍微解释一下,以便给人留下更有益的印象。
    猜你喜欢
    • 1970-01-01
    • 2011-08-28
    • 2018-04-12
    • 2016-04-19
    • 2013-10-13
    • 2012-08-26
    • 2012-05-20
    • 2014-11-18
    • 2018-03-21
    相关资源
    最近更新 更多