admin管理员组文章数量:1024945
spring and jsf both work on their own without any issues so I'm only including code which is relevant for the spring-jsf connection.
managed bean:
import jakarta.annotation.PostConstruct;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
import .springframework.beans.factory.annotation.Autowired;
import .springframework.web.context.support.SpringBeanAutowiringSupport;
import java.io.Serializable;
@Named
@ViewScoped
public class ZManagedBean extends SpringBeanAutowiringSupport implements Serializable{
private static final long serialVersionUID = 1L;
@PostConstruct
public void init() {
System.out.println(getzService());
}
@Autowired
ZService zService;
public ZService getzService() {return zService;}
public void setzService(ZService zService) {this.zService = zService;}
public void register() {
System.out.println("jsf alone works");
zService.checkInjection();
}
}
its deploying successfully but gives an error when calling register().
important logs:
[INFO] [] [jakarta.enterprise.logging.stdout] [tid: _ThreadID=73 _ThreadName=admin-listener(3)] [levelValue: 800] [[
.demoNoBoot2.zdemo.ZService@2816d266]]
first time initializing the managed bean, the service is injected successfully within the PostConstruct, but calling register() gives nullptrexc
[FATAL] [faces.context.exception.handler.log] [jakarta.enterprise.resource.webcontainer.faces.context] [tid: _ThreadID=59 _ThreadName=http-listener-1(3)] [levelValue: 1100] [[
Cannot invoke ".demoNoBoot2.zdemo.ZService.checkInjection()" because "this.zService" is null]]
as the managed bean gets instantiated again (ViewScoped), injection fails (also in PostConstruct).
Making the managed bean @ApplicationScoped doesn't fix the problem (it still prints the zService address in the logs and also prints it again later (I think when I first call the page) but this time with zService address null)
spring and jsf both work on their own without any issues so I'm only including code which is relevant for the spring-jsf connection.
managed bean:
import jakarta.annotation.PostConstruct;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
import .springframework.beans.factory.annotation.Autowired;
import .springframework.web.context.support.SpringBeanAutowiringSupport;
import java.io.Serializable;
@Named
@ViewScoped
public class ZManagedBean extends SpringBeanAutowiringSupport implements Serializable{
private static final long serialVersionUID = 1L;
@PostConstruct
public void init() {
System.out.println(getzService());
}
@Autowired
ZService zService;
public ZService getzService() {return zService;}
public void setzService(ZService zService) {this.zService = zService;}
public void register() {
System.out.println("jsf alone works");
zService.checkInjection();
}
}
its deploying successfully but gives an error when calling register().
important logs:
[INFO] [] [jakarta.enterprise.logging.stdout] [tid: _ThreadID=73 _ThreadName=admin-listener(3)] [levelValue: 800] [[
.demoNoBoot2.zdemo.ZService@2816d266]]
first time initializing the managed bean, the service is injected successfully within the PostConstruct, but calling register() gives nullptrexc
[FATAL] [faces.context.exception.handler.log] [jakarta.enterprise.resource.webcontainer.faces.context] [tid: _ThreadID=59 _ThreadName=http-listener-1(3)] [levelValue: 1100] [[
Cannot invoke ".demoNoBoot2.zdemo.ZService.checkInjection()" because "this.zService" is null]]
as the managed bean gets instantiated again (ViewScoped), injection fails (also in PostConstruct).
Making the managed bean @ApplicationScoped doesn't fix the problem (it still prints the zService address in the logs and also prints it again later (I think when I first call the page) but this time with zService address null)
本文标签:
版权声明:本文标题:can't inject(?) spring @Service bean into jsf @Named managed bean via SpringBeanAutowiringSupport and @Autowired - Stack 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745618378a2159427.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论