Spring + Maven:匹配的通配符是严格的,但是没有找到元素'jdbc:embedded-database'的声明 [英] Spring + Maven: The matching wildcard is strict, but no declaration can be found for element 'jdbc:embedded-database'

查看:136
本文介绍了Spring + Maven:匹配的通配符是严格的,但是没有找到元素'jdbc:embedded-database'的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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


匹配的通配符是strict,但是找不到元素'jdbc:embedded-database'的声明

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

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

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.

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

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

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

This is my spring-configuration-file, which causes the error during initialization of the 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>

这是我的pom.xml:

This is my 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>


推荐答案

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

This line in your Spring context file:

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

应更改为:

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

不确定你正在使用哪个IDE,但有一些(例如IntelliJ),这会被标记为错误并节省很多麻烦!

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!

这篇关于Spring + Maven:匹配的通配符是严格的,但是没有找到元素'jdbc:embedded-database'的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆