Spring Boot:错误 - "从jdbcTemplate执行的方法引用缺少DataAccessException"

时间:2017-12-07 09:22:26

标签: spring eclipse maven spring-boot

我是春季启动的新手,并尝试在Spring的网站上展示的一些例子。 我在尝试这个简单示例时遇到了上述错误 - https://spring.io/guides/gs/relational-data-access/

我正面临一个编译错误 - '来自JdbcTemplate类型的方法execute(String)引用了缺少的类型DataAccessException'。

图片 -

https://i.stack.imgur.com/8PL0m.jpg

我确实搜索了其他资源以摆脱这个问题,其中spring-tx / spring.transations建议附加这样的jar。在我的案例中没有任何效果。

POM.xml具有以下依赖性 -

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Added for COnsuming Restful services guide -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>

        <!-- Following three Added for Validating form validate with spring -->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-el</artifactId>
        </dependency>

        <!-- Following two are Added for relational data access using spring guide -->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
  </pluginRepositories>
</project>

如果有人可以帮帮我吗?万分感谢!

更新 spring-boot-starter-jdbc 的maven依赖关系树:

com.kurshit.springrest:SpringRest:war:0.0.1-SNAPSHOT
+- org.springframework.boot:spring-boot-starter-web:jar:1.5.9.RELEASE:compile
|  +- org.springframework.boot:spring-boot-starter:jar:1.5.9.RELEASE:compile
|  |  +- org.springframework.boot:spring-boot:jar:1.5.9.RELEASE:compile
|  |  |  +- (org.springframework:spring-core:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|  |  |  \- (org.springframework:spring-context:jar:4.3.13.RELEASE:compile - omitted for duplicat
|  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.9.RELEASE:compile
|  |  |  \- (org.springframework.boot:spring-boot:jar:1.5.9.RELEASE:compile - omitted for duplica
|  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.9.RELEASE:compile
|  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
|  |  |  |  +- ch.qos.logback:logback-core:jar:1.1.11:compile
|  |  |  |  \- (org.slf4j:slf4j-api:jar:1.7.25:compile - version managed from 1.6.6; omitted for
|  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
|  |  |  |  \- (org.slf4j:slf4j-api:jar:1.7.25:compile - version managed from 1.7.22; omitted for
|  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
|  |  |  |  \- (org.slf4j:slf4j-api:jar:1.7.25:compile - version managed from 1.7.22; omitted for
|  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
|  |  |     \- (org.slf4j:slf4j-api:jar:1.7.25:compile - version managed from 1.7.22; omitted for
|  |  +- org.springframework:spring-core:jar:4.3.13.RELEASE:compile
|  |  \- org.yaml:snakeyaml:jar:1.17:runtime
|  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.9.RELEASE:compile
|  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.23:compile
|  |  |  \- org.apache.tomcat:tomcat-annotations-api:jar:8.5.23:compile
|  |  +- (org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.23:compile - omitted for duplicate)
|  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.23:compile
|  |     \- (org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.23:compile - omitted for duplicate
|  +- (org.hibernate:hibernate-validator:jar:5.3.6.Final:compile - omitted for duplicate)
|  +- (com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile - omitted for duplicate)
|  +- org.springframework:spring-web:jar:4.3.13.RELEASE:compile
|  |  +- org.springframework:spring-aop:jar:4.3.13.RELEASE:compile
|  |  |  +- (org.springframework:spring-beans:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|  |  |  \- (org.springframework:spring-core:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|  |  +- org.springframework:spring-beans:jar:4.3.13.RELEASE:compile
|  |  |  \- (org.springframework:spring-core:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|  |  +- org.springframework:spring-context:jar:4.3.13.RELEASE:compile
|  |  |  +- (org.springframework:spring-aop:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|  |  |  +- (org.springframework:spring-beans:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|  |  |  +- (org.springframework:spring-core:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|  |  |  \- (org.springframework:spring-expression:jar:4.3.13.RELEASE:compile - omitted for dupli
|  |  \- (org.springframework:spring-core:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|  \- org.springframework:spring-webmvc:jar:4.3.13.RELEASE:compile
|     +- (org.springframework:spring-aop:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|     +- (org.springframework:spring-beans:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|     +- (org.springframework:spring-context:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|     +- (org.springframework:spring-core:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|     +- org.springframework:spring-expression:jar:4.3.13.RELEASE:compile
|     |  \- (org.springframework:spring-core:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|     \- (org.springframework:spring-web:jar:4.3.13.RELEASE:compile - omitted for duplicate)
+- org.springframework.boot:spring-boot-starter-test:jar:1.5.9.RELEASE:test
|  +- org.springframework.boot:spring-boot-test:jar:1.5.9.RELEASE:test
|  |  \- (org.springframework.boot:spring-boot:jar:1.5.9.RELEASE:test - omitted for duplicate)
|  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.9.RELEASE:test
|  |  +- (org.springframework.boot:spring-boot-test:jar:1.5.9.RELEASE:test - omitted for duplicat
|  |  \- (org.springframework.boot:spring-boot-autoconfigure:jar:1.5.9.RELEASE:test - omitted for
|  +- (com.jayway.jsonpath:json-path:jar:2.2.0:test - omitted for duplicate)
|  +- junit:junit:jar:4.12:test
|  |  \- (org.hamcrest:hamcrest-core:jar:1.3:test - version managed from 1.1; omitted for duplica
|  +- org.assertj:assertj-core:jar:2.6.0:test
|  +- org.mockito:mockito-core:jar:1.10.19:test
|  |  +- (org.hamcrest:hamcrest-core:jar:1.3:test - version managed from 1.1; omitted for duplica
|  |  \- org.objenesis:objenesis:jar:2.1:test
|  +- org.hamcrest:hamcrest-core:jar:1.3:test
|  +- org.hamcrest:hamcrest-library:jar:1.3:test
|  |  \- (org.hamcrest:hamcrest-core:jar:1.3:test - version managed from 1.1; omitted for duplica
|  +- org.skyscreamer:jsonassert:jar:1.4.0:test
|  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
|  +- (org.springframework:spring-core:jar:4.3.13.RELEASE:compile - scope updated from test; omit
|  \- org.springframework:spring-test:jar:4.3.13.RELEASE:test
|     \- (org.springframework:spring-core:jar:4.3.13.RELEASE:test - omitted for duplicate)
+- com.jayway.jsonpath:json-path:jar:2.2.0:test
|  +- net.minidev:json-smart:jar:2.2.1:test
|  |  \- net.minidev:accessors-smart:jar:1.1:test
|  |     \- org.ow2.asm:asm:jar:5.0.3:test
|  \- (org.slf4j:slf4j-api:jar:1.7.25:compile - version managed from 1.7.16; scope updated from t
+- com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile
|  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
|  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile
+- org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.5.9.RELEASE:compile
|  +- (org.springframework.boot:spring-boot-starter:jar:1.5.9.RELEASE:compile - omitted for dupli
|  +- (org.springframework.boot:spring-boot-starter-web:jar:1.5.9.RELEASE:compile - omitted for d
|  +- org.thymeleaf:thymeleaf-spring4:jar:2.1.6.RELEASE:compile
|  |  +- org.thymeleaf:thymeleaf:jar:2.1.6.RELEASE:compile
|  |  |  +- ognl:ognl:jar:3.0.8:compile
|  |  |  +- org.javassist:javassist:jar:3.21.0-GA:compile (version managed from 3.16.1-GA)
|  |  |  +- org.unbescape:unbescape:jar:1.1.0.RELEASE:compile
|  |  |  \- (org.slf4j:slf4j-api:jar:1.7.25:compile - version managed from 1.6.6; omitted for dup
|  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
|  \- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.4.0:compile
|     +- org.codehaus.groovy:groovy:jar:2.4.13:compile (version managed from 2.4.3)
|     \- (org.thymeleaf:thymeleaf:jar:2.1.6.RELEASE:compile - version managed from 2.1.4.RELEASE;
+- org.hibernate:hibernate-validator:jar:5.3.6.Final:compile
|  +- javax.validation:validation-api:jar:1.1.0.Final:compile
|  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile (version managed from 3.3.0.Final)
|  \- com.fasterxml:classmate:jar:1.3.4:compile (version managed from 1.3.1)
+- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.23:compile
+- org.springframework.boot:spring-boot-starter-jdbc:jar:1.5.9.RELEASE:compile
|  +- (org.springframework.boot:spring-boot-starter:jar:1.5.9.RELEASE:compile - omitted for dupli
|  +- org.apache.tomcat:tomcat-jdbc:jar:8.5.23:compile
|  |  \- org.apache.tomcat:tomcat-juli:jar:8.5.23:compile
|  \- org.springframework:spring-jdbc:jar:4.3.13.RELEASE:compile
|     +- (org.springframework:spring-beans:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|     +- (org.springframework:spring-core:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|     \- org.springframework:spring-tx:jar:4.3.13.RELEASE:compile
|        +- (org.springframework:spring-beans:jar:4.3.13.RELEASE:compile - omitted for duplicate)
|        \- (org.springframework:spring-core:jar:4.3.13.RELEASE:compile - omitted for duplicate)
\- com.h2database:h2:jar:1.4.196:compile

1 个答案:

答案 0 :(得分:0)

添加以下依赖项(您可能必须调整版本以与Spring Boot版本兼容)

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

编辑:   从maven repo中删除冲突的依赖项让我摆脱了这个编译错误。