2017-11-08 15 views
0

스프링 부트, JSF 및 MyBatis를 사용하고 있습니다. 문제는 MyBatis 매퍼를 사용할 때 NullPointerException이 발생한다는 것입니다. MyBatis 연결이 작동 중입니다. OK, Autowired를 사용하여 유닛 테스트에서 테스트했습니다 (Service 클래스에서 수행하는 것과 같은 방식).JSF에서 Autowired를 사용할 때 NullPointerException이 발생했습니다.

이 내 JSF 컨트롤러 :

@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 I autowire가 주석을 사용하고있는 경우 weatherMapper가 null 왜

@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(); 
    } 

} 

?

답변

-1

"weatherMapper"클래스를 체크인해야합니다. 쿼리가 null을 반환한다고 생각합니다.

+0

귀하의 의견을 보내 주셔서 감사합니다. 그러나 쿼리 결과가 null 인 경우 컨트롤러에서 getWheather 메서드의 반환 값을 사용하면 예외가 발생합니다. –

관련 문제