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)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745618380a4636372.html
评论列表(0条)