1

我想将 spring autowired 与 jdbc 结合用于初始 derby 数据和 jpa。

目前我尝试这样的配置文件:

         <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:context="http://www.springframework.org/schema/context"
          xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
          xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd        
                http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">

    <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" />
            <property name="url"
                value="jdbc:derby:target/database/message;create=true" />
            <property name="username" value="app" />
            <property name="password" value="app" />
        </bean>

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

        <jdbc:initialize-database data-source="dataSource">
            <jdbc:script location="classpath:resources/dbscripts/createDB.sql" />
        </jdbc:initialize-database>

...

        <tx:annotation-driven transaction-manager="transactionManager" /> 
...
    <context:component-scan base-package="com.ba" />
    <context:annotation-config />

不幸的是,无论我做什么,我都会遇到以下错误之一

Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/jdbc]

或相同的上下文,tx 命名空间

maven的pom.xml文件是:

      <properties>
    <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
    <org.openjpa.version>2.0.0</org.openjpa.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
      <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.2</version>      
    </dependency>

    <dependency>
        <groupId>commons-discovery</groupId>
        <artifactId>commons-discovery</artifactId>
        <version>20040218.194635</version>
    </dependency>

    <dependency>
    <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.1</version>
    </dependency>

    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.8</version>
    </dependency>

    <dependency>
        <groupId>commons-validator</groupId>
        <artifactId>commons-validator</artifactId>
        <version>1.3.1</version>
    </dependency>

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

    <dependency>
       <groupId>commons-lang</groupId>
       <artifactId>commons-lang</artifactId>
       <version>2.6</version>
    </dependency>           


    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

     <dependency>
      <groupId>org.apache.derby</groupId>
      <artifactId>derby</artifactId>
      <version>10.10.1.1</version>
    </dependency>

        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-jpa_3.0_spec</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa-all</artifactId>
            <version>${org.openjpa.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-jta_1.1_spec</artifactId>
            <version>1.1.1</version>
        </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

        <dependency>
               <groupId>javax.validation</groupId>
               <artifactId>validation-api</artifactId>
               <version>1.1.0.Final</version>
        </dependency>


    <dependency>
                 <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>
  </dependencies>

在stackoverflow中有很多关于它的主题,但要么没有上下文,要么没有jdbc或tx ...

有谁知道如何修理它?还是一个很好的免费工具?

4

1 回答 1

3

您缺少spring-jdbcjar(即托管 spring-jdbc-3.0.xsd)和spring-txjar(即托管 spring-tx.-3.0.xsd)。如果您使用 Maven 构建项目,请添加以下依赖项声明:

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring-framework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring-framework.version}</version>
        </dependency> 

您可能正在使用spring-framework.version的版本。3.0.X.RELEASE

于 2013-06-14T23:16:29.843 回答