JSF Spring @Autowired Issue

时间:2016-05-23 00:41:16

标签: spring spring-mvc jsf-2

我需要就以下问题提出建议:

我有一个JSF监听器,我想通过自动布线来调用spring bean。我在尝试从侦听器类调用userAuthService.getComponentSecurity()时遇到空指针异常。我正在使用

  • JSF 2.x
  • 春季3.2.4。释放
  • Tomcat 7.0.x

我错过了什么?请参阅下面的我的代码片段:

JSF侦听器代码:

@Component
public class FieldDisableListener implements SystemEventListener {

@Autowired
private UserAuthService userAuthService;

private void loadUserConfig() {
userAuthService.getComponentSecurity();
    ...
}  

接口类:

public interface UserAuthService {
public ComponentSecurity getComponentSecurity();
}

实施班级

@Service
public class UserAuthServiceImpl implements UserAuthService{
public ComponentSecurity getComponentSecurity() {
}

WEB-INF

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<!-- Add Support for Spring -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

的applicationContext.xml

<context:annotation-config/>
<context:component-scan base-package="com.san.security.service,"/>

面-config.xml中

<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
<system-event-listener>
    <system-event-listener-class>com.san.security.listeners.FieldDisableListener</system-event-listener-class>
    <system-event-class>javax.faces.event.PreRenderViewEvent</system-event-class>
</system-event-listener>
</application>

0 个答案:

没有答案