I am using Spring-boot, JSF and MyBatis. The problem is that I am getting a NullPointerException when I try to use MyBatis mapper. The MyBatis connection is working OK, I have tested it on my unit tests with Autowired (the same way I am doing it in the Service class).
This is my JSF controller:
@ManagedBean
@ViewScoped
public class WeatherView implements Serializable {
private List<Weather> weathers;
@ManagedProperty(value = WeatherService.EL_NAME)
private WeatherService weatherService;
@PostConstruct
public void init(){
setWeathers(this.weatherService.getAll());
}
public List<Weather> getWeathers() {
return this.weathers;
}
public void setWeathers(List<Weather> weathers) {
this.weathers = weathers;
}
public void setWeatherService(WeatherService weatherService) {
this.weatherService = weatherService;
}
WeatherService.java
@Service(WeatherService.BEAN_NAME)
@ManagedBean(name = WeatherService.BEAN_NAME)
@ApplicationScoped
public class WeatherService {
public static final String BEAN_NAME = "weatherService";
public static final String EL_NAME = "#{weatherService}";
@Autowired
private WeatherMapper weatherMapper; // <-- This is the MyBatis Mapper
// The NullPointerExceptions is thrown here
public List<Weather> getAll(){
return weatherMapper.getAll();
}
}
Why weatherMapper is null if I am using Autowired annotation?