I'm trying to use the Spring Framework in my project, but I have a problem with the import. I'm working with Gradle for builds, React JS for the front end and Java for the back end.
The weird thing is that I can use classes as RowMapper and JdbcTemplate (I can read and write in my database using these classes) even if VS Code is telling me that my import cannot be resolved.
When I build with Gradle (gradle build then gradle bootrun in my command prompt) it works too.
It's pretty boring working with errors that are not supposed to be present. Can someone help me ?
Personally I think it's an error in my build.gradle file or a configuration in my VS Code, but I'm not sure.
Here's my build.gradle with my dependencies and my repositories :
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
apply plugin: 'java'
apply plugin: 'org.liquibase.gradle'
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter:2.0.6.RELEASE")
// Use MySQL Connector-J
runtime 'mysql:mysql-connector-java:8.0.12'
compile("org.springframework:spring-jdbc:3.2.4.RELEASE")
testCompile('org.junit.jupiter:junit-jupiter-api:5.3.1')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.3.1')
compile ('commons-dbcp:commons-dbcp:1.4')
liquibaseRuntime 'org.liquibase:liquibase-core:3.6.1'
liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:2.0.1'
liquibaseRuntime 'mysql:mysql-connector-java:8.0.12'
}
Here's a class of my project where the error occurs :
package be.heh.petclinic.component.pet;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import be.heh.petclinic.domain.Pet;
public class JdbcPetDao {
private DataSource dataSource;
public JdbcPetDao(DataSource dataSource){
this.dataSource = dataSource;
}
public List<Pet> getPets() {
JdbcTemplate select = new JdbcTemplate(dataSource);
return select.query("SELECT name, birth_date, owner_id, type_id FROM pets", new PetRowMapper());
}
}
org.springframework is underlined and therefore JdbcTemplate as well.