autowired spring return null
@Controller
public class Controller {
@GetMapping("/example")
public String example() {
MyService my = new MyService();
my.doStuff();
}
}
@Service
public class MyService() {
@Autowired
MyRepository repo;
public void doStuff() {
repo.findByName( "steve" );
}
}
@Repository
public interface MyRepository extends CrudRepository<My, Long> {
List<My> findByName( String name );
}