简体   繁体   中英

Type JdbcDaoSupport cannot be resolved. It is indirectly referenced from required .class files error

I wanted to follow this answer from SO and tried to add the following code:

public class CustomJdbcUserDetailsService extends JdbcDaoImpl {

    @Override
    public List<GrantedAuthority> loadUserAuthorities(String username) {
        return super.loadUserAuthorities(username);
    }

}

in my Spring-Boot Project. Sadly I get the output:

The type org.springframework.jdbc.core.support.JdbcDaoSupport cannot be resolved. It is indirectly referenced from required .class files

So on research I tried to add some new dependencies (like suggested here )

eg:

   <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
    </dependency>

but it does not help. I tried to refresh (clean) the project but nothing changed. Can someone relate to this issue? I am using Spring Tool Suite btw.

You can try below steps in order:

  1. Add spring-jdbc dependency
  2. Do maven force update
  3. Delete .m2/repository folder and then do maven update as this can also happen due to corrupted local maven repository

Since you are using SpringBoot ,you can simply add the JDBC starter to your pom.xml in order to have JDBC support.

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

It will transitively give you spring-jdbc , spring-tx and HikariCP

You also need to include the JDBC driver in your pom.xml depending on what DB you are using.

Also remember to configure the DB access info in your application.properties , for example in case of Postgresql:

spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/
spring.datasource.username=admin 
spring.datasource.password=password
spring.datasource.driver-class-name=org.postgresql.Driver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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