java Spring + Maven:匹配通配符是严格的,但找不到元素'jdbc:embedded-database'的声明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10093547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 23:35:13  来源:igfitidea点击:

Spring + Maven: The matching wildcard is strict, but no declaration can be found for element 'jdbc:embedded-database'

javaspringmaven-3tomcat7spring-jdbc

提问by mavilein

i am currently trying to build a little webapp that uses Spring, Hibernate and Maven (running on a tomcat). It works quite fine, except that i cannot get my embedded-database to work. I hope you can help me.

我目前正在尝试构建一个使用 Spring、Hibernate 和 Maven(在 tomcat 上运行)的小网络应用程序。它工作得很好,除了我无法让我的嵌入式数据库工作。我希望你能帮助我。

I am always facing this error, when i am deploying the webapp to the Tomcat:

当我将 webapp 部署到 Tomcat 时,我总是面临这个错误:

The matching wildcard is strict, but no declaration can be found for element 'jdbc:embedded-database'

匹配的通配符是严格的,但找不到元素“jdbc:embedded-database”的声明

During my investigations i learned that this message is pointing towards missing libraries. Therefore i added my pom.xml, where i added the artifact spring-jdbc.

在我的调查中,我了解到此消息指向缺少的库。因此我添加了我的 pom.xml,在那里我添加了工件 spring-jdbc。

Can you help me finding the error? Thanks a lot!

你能帮我找出错误吗?非常感谢!



This is my spring-configuration-file, which causes the error during initialization of the webapp:

这是我的 spring-configuration-file,它在 webapp 初始化期间导致错误:

<?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:jdbc="http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
   http://www.springframework.org/schema/tx 
   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
   http://www.springframework.org/schema/jdbc 
   http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd">
   <bean id="sessionFactory" class=
    "org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
       <property name="dataSource" ref="embeddedDatasource" />
       <property name="packagesToScan" value="org.rest" />
        <property name="hibernateProperties">
            <value>
                hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
                hibernate.hbm2ddl.auto=update
                hibernate.show_sql=false
            </value>
        </property>
    </bean>

    <jdbc:embedded-database id="embeddedDatasource" type="HSQL"/>

    <bean id="txManager" class=
        "org.springframework.orm.hibernate3.HibernateTransactionManager">
       <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <tx:annotation-driven transaction-manager="txManager" />
</beans>

This is my 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.marcus</groupId>
  <artifactId>maven-webapp-archetype</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>maven-webapp-archetype 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>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>3.0-alpha-1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp.jstl</groupId>
        <artifactId>javax.servlet.jsp.jstl-api</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.6.10.Final</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
  </dependencies>
  <build>
    <finalName>maven-webapp-archetype</finalName>
    <plugins>
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat6-maven-plugin</artifactId>
          <version>2.0-beta-1</version>
          <configuration>
            <url>http://localhost:8080/manager/html</url>
            <server>tomcat7</server>
          </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.0-beta-1</version>
            <configuration>
                <url>http://localhost:8080/manager/html</url>
                <server>tomcat7</server>
            </configuration>
        </plugin>
    </plugins>
  </build>
</project>

回答by darrengorman

This line in your Spring context file:

您的 Spring 上下文文件中的这一行:

xmlns:jdbc="http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd"

should be changed to :

应改为:

xmlns:jdbc="http://www.springframework.org/schema/jdbc"

Not sure what IDE you're using but with some (IntelliJ for example) this would be flagged as an error and save a lot of headache!

不确定您使用的是什么 IDE,但对于某些(例如 IntelliJ),这将被标记为错误并省去很多麻烦!

回答by Paul Verest

For me it was to add xmlns:jdbc and xsi:schemaLocation

对我来说是添加 xmlns:jdbc 和 xsi:schemaLocation

<beans ....

    xmlns:jdbc="http://www.springframework.org/schema/jdbc"

    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    .....
    http://www.springframework.org/schema/jdbc
    http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd"
    default-lazy-init="true">

also add

还添加