我不能注射使用@Autowired服務。@Autowired JSF 2彈簧3空
AplicationContext.xml
<context:component-scan base-package="com.mypackage" />
<context:component-scan base-package="com.mypackage.bean" />
<context:component-scan base-package="com.mypackage.dao" />
<context:component-scan base-package="com.mypackage.service" />
<context:component-scan base-package="com.mypackage.filters" />
<context:annotation-config />
faces-config.xml中
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver></application>
的web.xml
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
服務聲明:
@Service
public class UsuarioServiceImpl extends GenericServiceImpl implements UsuarioService{...}
個
ManagedBean:
@ManagedBean(name="cadastroUsuarioMB")
@SessionScoped
public class CadastroUsuarioBean {
@Autowired
UsuarioService usuarioService;
private Usuario usuario = new Usuario();
public String salvar() {
//Error !!! usuarioService is null !
usuarioService.retornaUsuarioPorLogin(usuario.getEmail(), usuario.getSenha());
JsfUtil.addSuccessMessage(null, usuario.getCelular());
return "";
}
}
我解決了!更換@ManagedBean(name = 「cadastroUsuarioMB」),以@Component( 「cadastroUsuarioMB」) – user3229393
很高興,這有助於你。 – Prasad