块引用
我正在尝试使用 Seam 3 制作一个 REST 应用程序。Hello world 运行良好。但是我尝试在带有注释 @Inject 的 Rest Application 中使用注入,但该对象仍然为空。
是否有人有一段代码可以初始化 REST 类中调用的组件?
多谢。web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
</web-app>
REST 应用程序
@ApplicationPath("object")
@Path("creation")
@RequestScoped
public class ObjectApplication extends javax.ws.rs.core.Application {
@Inject
ObjectManager objectManager;
....
@POST
@GET
@Path("create")
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_XML)
public String createObject(ObjectType objectType) {
...
}
}
和对象管理器
@Stateless
public class ObjectManager {
}
.
20:30:50,362 INFO [org.jboss.weld.deployer] (MSC service thread 1-5) JBAS016008: Starting weld service for deployment ObjectRest.war
20:30:50,420 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC00001: Failed to start service jboss.deployment.unit."ObjectRest.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."ObjectRest.war".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [ObjectManager] with qualifiers [@Default] at injection point [[field] @Inject com.qc.api.rest.ObjectApplication.objectManager]