[英]Injecting Stateless EJB into Named Bean
跟随一个教程,陷入一个问题。 系统:wildfly 10,带有多模块的maven项目,包装:耳
EJB:
@Stateless
public class ToyService implements ToyServiceRemote, ToyServiceLocal {
...
}
接口:
@Local
public interface ToyServiceLocal {
...
}
豆角,扁豆:
@Named("toyProducts")
@RequestScoped
public class ProductBean {
@Inject
private ToyServiceLocal toyService;
@PostConstruct
public void initialize() {
toyList = toyService.getAllToys();
}
...
}
JSF:
<ui:repeat value="#{toyProducts.toyList}" var="toy">
...
</ui:repeat>
应用程序已部署,但是当我尝试在浏览器中打开页面时,我得到:
错误[io.undertow.request](默认任务62)UT005023:对/index.xhtml的异常处理请求:javax.servlet.ServletException:无法设置com.example.common.service.ToyServiceLocal字段shop.beans.ProductBean。 toycom到com.example.product.service.ToyServiceLocal $ ToyServiceRemote $ 1303029808 $ Proxy $ _ $$ _ Weld $ EnterpriseProxy $ at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)wildfly-experiment | 在io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)wildfly-experiment | 在io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)上Wildfly-experiment | 在io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)...
这次,我找到了“真正的”答案:由于我正在使用打包为EAR(带有某些EJB,通用JAR和WAR文件)的多模块maven项目。 我要做的就是添加WAR文件中提供的范围(常见的是JAR和EJB中的产品)
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>product</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.