bob
bob

Reputation: 31

exception occurs when NamedParameterJdbcTemplate is used

When I use NamedParameterJdbcTemplate, I get an exception "No class Def Found Error".But when I use JdbcTemplate I don't get any exception.It works.The exception only happens when I use NamedParameterJdbcTemplate.I get the following exception.

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

Can anyone please help me.

Upvotes: 1

Views: 9185

Answers (5)

Ajay Takur
Ajay Takur

Reputation: 6236

Make sure to have all these dependencies in 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>

Upvotes: 0

Muneeb
Muneeb

Reputation: 1

I faced the same issue. What I did...in my eclipse>Project explorer>Project>Maven dependencies. It showed me some 3.0.0 version of spring dependencies were included. I simply right click all one by one select Maven from the options and then Exclude Maven Artifacts. After that, I added all the spring 4.3.9 dependencies in pom. It worked.

Upvotes: 0

yokeho
yokeho

Reputation: 177

Same Spring core version issue for me. I had this in my pom.xml:

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

and was getting the java.lang.NoClassDefFoundError.

I replaced that with:

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

And then everything worked fine.

Upvotes: 2

Andrew
Andrew

Reputation: 37969

I got the same error when I use in maven <spring.version>3.2.0.RELEASE</spring.version>,

Then I change to <spring.version>4.0.2. RELEASE</spring>. version, and now It's working well.

Upvotes: 0

Jorge_B
Jorge_B

Reputation: 9872

Make sure you include all your execution dependencies. I suggest you consider some automated build tool with a declarative dependencies management. For example maven could package your application with every transitive dependency you need just with the fragment you can find in http://projects.spring.io/spring-framework/ :

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

Upvotes: 4

Related Questions