Reputation: 193
I'm trying to get a CrudRepository to work:
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.codynx.itemizer.model.Task;
@Repository
public interface TaskMysqlRepository extends CrudRepository<Task, Integer> {
}
used here:
import java.sql.ResultSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.codynx.itemizer.model.Task;
import com.codynx.itemizer.repository.TaskMysqlRepository;
@Service
public class TaskMysqlService {
public ResultSet resultSet = null;
private Iterable<Task> tasks;
@Autowired
private TaskMysqlRepository taskMysqlRepository;
public TaskMysqlService() {
}
public Iterable<Task> getTasks(){
return taskMysqlRepository.findAll();
}
}
But I get the error message:
required a bean of type 'com.codynx.itemizer.repository.TaskMysqlRepository' that could not be found
The repo is there and has the correct annotation. What am I doing wrong?
Here is also the Task Type:
[...]
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class Task {
@JsonProperty(access = Access.READ_ONLY)
@Id
private String id;
@Version
private Long version;
private LocalDateTime start;
private LocalDateTime due;
private boolean done;
private String name;
private Integer parent_id;
}
Is it because of some type missmatch? I mean the repo is there...
Upvotes: 0
Views: 1839
Reputation: 721
May be in your case due to package structure, autoconfiguration is not happening.
Try adding @EnableJpaRepositories
and @EntityScan
and mention the packages.
@SpringBootApplication
@EntityScan(basePackages = {"com.entities.package"}) //your entities package goes here
@EnableJpaRepositories(basePackages = {"com.repositories.package"})//your repository package goes here
public class SpringBootDataJpaApplication
{
public static void main(String[] args)
{
SpringApplication.run(SpringBootDataJpaApplication.class, args);
}
}
Upvotes: 1