Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDavid Sampimon
12,026 Pointserror: method save in interface CrudRepository<T,ID> cannot be applied to given types; courses.save(bunchOfCourses);
I am following along with the 'Build a REST API in Spring' workshop. However, when trying to run the application during the 'populating and relationships' video I get the below error. I tried dowloading the project provided with the video 's1v6', which throws the same error . Please help, since I am completely stuck.
C:\course-reviews-api\src\main\java\com\teamtreehouse\core\DatabaseLoader.java:54: error: method save in interface CrudRepository<T,ID> cannot be applied to given types;
courses.save(bunchOfCourses);
^
required: S
found: List<Course>
reason: inferred type does not conform to upper bound(s)
inferred: List<Course>
upper bound(s): Course
where S,T,ID are type-variables:
S extends Course declared in method <S>save(S)
T extends Object declared in interface CrudRepository
ID extends Object declared in interface CrudRepository
The only change I made to the downloaded project is in the build.gradle file, since this was also throwing an error. My build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootJar {
baseName = 'gs-accessing-data-rest'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-rest")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.h2database:h2")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
1 Answer
david101
2,089 PointsI don’t know what version of spring is being used for the course but it seems that the “save” method relates to version 1.5 and version 2 uses the saveAll method. Looks you are using version from your grade script.
Have a look at line 54 in your DatabaseLoader class