I am experimenting with spring and MongoDB. In my project I have a repository and a service which has a scheduled method. The problem is, that the repository doesn't get autowired, it is always null.
Am I missing somethig?
directory
MachineApplication.java
@SpringBootApplication
@EnableScheduling
public class MachineApplication {
public static void main(String[] args) {
SpringApplication.run(MachineApplication.class, args);
}
}
Worker.java
@Service
public class Worker {
@Autowired
private LineDataRepository lineDataRepository;
@Autowired
private LineRepository lineRepository;
...
public Worker() {
System.out.println("--------------------------------");
System.out.println(lineDataRepository);//null
System.out.println(lineRepository);//null
}
}
LineDataRepository
@Repository
public interface LineDataRepository extends MongoRepository<LineData, String> {
}
Add @EnableMongoRepositories
to the MachineApplication to let it detect Mongo repositories.
See here
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments