0

I am using Hikari CP anf JDBC Template to insert incoming request parameters in a Controller to database.

So I Do the following:

@RestController
public class HomeController  {

@Autowired
    private JdbcTemplate jtm;


@RequestMapping(value="/insert/data",produces={MediaType.APPLICATION_JSON_VALUE},method=RequestMethod.GET)
    public ResponseEntity<?> insertData(@RequestParam("id")int id ,@RequestParam("name")String name) throws IOException, ClassNotFoundException, SQLException{


           String sql = "INSERT INTO public.users(id, name) VALUES (?, ?, ?);";


            jtm.update(sql,id,name);


}
}

But this throws the following error:

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

I have a hikari.properties in /src/main/resources

driverClassName=org.postgresql.Driver
jdbcUrl=jdbc:postgresql://10.1.9.72:5432/data_base
maximumPoolSize=20
username=user
password=password
dataSource.cachePrepStmts=true
dataSource.prepStmtCacheSize=250
dataSource.prepStmtCacheSqlLimit=2048

My Configuration Java Class for HikariCP

AppConfig.java

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AppConfig {

    @Bean(destroyMethod = "close")
    public DataSource dataSource() throws SQLException {
        HikariConfig config = new HikariConfig("/hikari.properties");
        HikariDataSource dataSource = new HikariDataSource(config);

        return dataSource;
    }
}

I added the following dependencies as well (Hikari Cp ,Spring JBDC ,spring-tx) in my pom.xml

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


    <dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP-java7</artifactId>
        <version>2.4.12</version>
    </dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>3.0.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>3.2.1.RELEASE</version>
</dependency>

Any help is appreciated

Ricky
  • 2,662
  • 5
  • 25
  • 57
  • Possible duplicate of [Eclipse error: indirectly referenced from required .class files?](https://stackoverflow.com/questions/5547162/eclipse-error-indirectly-referenced-from-required-class-files) – tima Jul 26 '17 at 01:46
  • possibly missing the `spring-jdbc` dependency – tima Jul 26 '17 at 01:47
  • @tima No I added the 4 depencies as well.but still throwing the error – Ricky Jul 26 '17 at 01:51

0 Answers0