内
我正在尝试构建一个带有Spring
+ JSF
的基本网页。基本上,我有一个HelloController
和HelloSpringService
.它在类HelloController
返回helloSpringService.sayHello();
行上给出错误。
public class HelloController {
@ManagedProperty("#{helloSpringService)")
private HelloSpringService helloSpringService;
public String showHello() {
return helloSpringService.sayHello();
}
public void setHelloSpringService(HelloSpringService helloSpringService) {
this.helloSpringService = helloSpringService;
}
public HelloSpringService getHelloSpringService() {
return helloSpringService;
}
}
import org.springframework.stereotype.Service;
@Service
public class HelloSpringService {
public String sayHello() {
return "hellofromspringservice";
}
}
使用 @Autowired
而不是 @ManagedProperty("#{helloSpringService)")
您已经创建了 bean HelloSpringService 作为服务 bean,因此 Spring 核心负责 bean 的生命周期,因此您必须使用 @Autowired 而不是 @ManagedProperty 来调用它。
helloSpringService
应自动连线,而不是作为托管属性包含在