繁体   English   中英

使用 NamedParameterJdbcTemplate 时发生异常

[英]exception occurs when NamedParameterJdbcTemplate is used

当我使用NamedParameterJdbcTemplate ,我得到一个异常"No class Def Found Error" 。但是当我使用 JdbcTemplate 时我没有得到任何异常。它有效。只有当我使用NamedParameterJdbcTemplate时才会发生异常。我得到以下异常。

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/SpringProperties
    at org.springframework.jdbc.core.StatementCreatorUtils.<clinit>(StatementCreatorUtils.java:80)
    at org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource.getSqlType(BeanPropertySqlParameterSource.java:103)
    at org.springframework.jdbc.core.namedparam.NamedParameterUtils.buildSqlParameterList(NamedParameterUtils.java:415)
    at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.getPreparedStatementCreator(NamedParameterJdbcTemplate.java:373)
    at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:311)
    at com.harsh.spring.test.OffersDAO.update(OffersDAO.java:49)
    at com.harsh.spring.test.App.main(App.java:21)
Caused by: java.lang.ClassNotFoundException: org.springframework.core.SpringProperties

谁能帮帮我吗。

确保包含所有执行依赖项。 我建议您考虑一些具有声明性依赖项管理的自动构建工具。 例如,maven 可以将您的应用程序与您需要的每个传递依赖项打包在一起,只需使用您可以在http://projects.spring.io/spring-framework/ 中找到的片段:

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.0.2.RELEASE</version>
    </dependency>
</dependencies>

对我来说同样的 Spring 核心版本问题。 我的pom.xml有这个:

<dependency>
    <groupId>springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>1.2.6</version>
</dependency>

并且得到java.lang.NoClassDefFoundError

我将其替换为:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.1.1.RELEASE</version>
</dependency>

然后一切正常。

我在 maven <spring.version>3.2.0.RELEASE</spring.version>使用时遇到了同样的错误,

然后我更改为<spring.version>4.0.2. RELEASE</spring> <spring.version>4.0.2. RELEASE</spring> 版本,现在运行良好。

我遇到了同样的问题。 我做了什么......在我的 eclipse>Project explorer>Project>Maven 依赖项中。 它向我展示了一些 3.0.0 版本的 spring 依赖项。 我只需右键单击所有选项,从选项中一一选择 Maven,然后排除 Maven Artifacts。 之后,我在 pom.xml 中添加了所有 spring 4.3.9 依赖项。 有效。

确保在pom.xml有所有这些依赖项

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>       
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM