The following code snippet works in a Spring Boot 1.5.7 application.
@Controller
public class MainController {
@Autowired
private EventtypeRepository eventtypeRepository;
private BetfairFacade client = new BetfairFacade();
@GetMapping(path="/update")
public @ResponseBody int updateBetfair() {
return client.updateBetfair(eventtypeRepository);
}
}
public class BetfairFacade {
public BetfairFacade() {
}
public int updateBetfair(EventtypeRepository eventtypeRepository) {
int out = 0;
Eventtype bfT = new Eventtype();
bfT.setEventtype("foo");
bfT.setName("bar");
eventtypeRepository.save(bfT);
return out;
}
}
The following snippet does NOT work because when I try to instantiate eventtypeRepository
in BetfairFacade
the field remains null
.
@Controller
public class MainController {
private BetfairFacade client = new BetfairFacade();
@GetMapping(path="/update")
public @ResponseBody int updateBetfair() {
return client.updateBetfair();
}
}
@Component
public class BetfairFacade {
@Autowired
public EventtypeRepository eventtypeRepository;
public BetfairFacade() {
}
public int updateBetfair() {
int out = 0;
Eventtype bfT = new Eventtype();
bfT.setEventtype("foo");
bfT.setName("bar");
eventtypeRepository.save(bfT);
return out;
}
}
Why does not this work? Is it possible to get this working, if so how?