泽西岛 2.22 UnsatisfiedDependencyException
Jersey 2.22 UnsatisfiedDependencyException
我正在使用 Wildfly 10 和 Java 8。我尝试绑定我的服务 like here 但我仍然收到此错误。我能看到的唯一区别是 pom.xml 依赖项,但是 2.0-rc1 版本是旧的。
[io.undertow.request] (default task-2) UT005023: Exception handling request to /api/account: javax.servlet.ServletException: A MultiException has 3 exceptions. They are:
1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=ICuentaService,parent=CuentaServiceRS,qualifiers={},position=-1,optional=false,self=false,unqualified=null,287721117)
2. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of ar.com.olx.api.rest.CuentaServiceRS errors were found
3. java.lang.IllegalStateException: Unable to perform operation: resolve on ar.com.olx.api.rest.CuentaServiceRS
我的 API 休息 class
@Path("/account")
public class CuentaServiceRS {
@Inject
private ICuentaService cuentaService;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Cuenta getCuenta() {
return cuentaService.getCuentas().get(0);
}
}
pom.xml
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.22.2</version>
</dependency>
web.xml
<servlet>
<servlet-name>altitudeservlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>ar.com.villat.bind.ApplicationJaxRS</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
我的应用程序 JAX-RS class
public class ApplicationJaxRS extends ResourceConfig {
public ApplicationJaxRS(){
register(new CustomBinder());
packages(true, "ar.com.villat");
}
}
最后,我的自定义活页夹
public class CustomBinder extends AbstractBinder {
@Override
protected void configure() {
bind(ICuentaService.class).to(CuentaServiceImpl.class);
}
}
如果您需要更多详细信息,请告诉我
在AbstractBinder
中,应该是bind(Implementation).to(Contract)
。你有相反的方式。他们这样做的原因是一个实现可能有多个合同,所以你可以只链接 to
调用。
从 :
更改 CustomBinder 实现
@Override
protected void configure() {
bind(ICuentaService.class).to(CuentaServiceImpl.class);
}
到
@Override
protected void configure() {
bind(ICuentaService.class).to(CuentaServiceImpl.class);
}
应该适合你。
换句话说,我建议按照以下思路创建接口:
public interface ICuenta {
// define an API
Cuenta getCeunta();
}
然后在class中实现为
public class ICuentaService implements ICuenta {
// implement the API
Cuenta getCeunta() {
// get it form somewher and return;
}
}
并将它们绑定为
@Override
protected void configure() {
bind(ICuenta.class).to(ICuentaService.class);
}
并在您的资源 class 中进一步使用它作为:
ICuenta icuenta;
@Inject
public CuentaServiceRS(ICuenta icuenta) {
this.icuenta = icuenta;
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public Cuenta getCuenta() {
return icuenta.getCeunta();
}
我正在使用 Wildfly 10 和 Java 8。我尝试绑定我的服务 like here 但我仍然收到此错误。我能看到的唯一区别是 pom.xml 依赖项,但是 2.0-rc1 版本是旧的。
[io.undertow.request] (default task-2) UT005023: Exception handling request to /api/account: javax.servlet.ServletException: A MultiException has 3 exceptions. They are:
1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=ICuentaService,parent=CuentaServiceRS,qualifiers={},position=-1,optional=false,self=false,unqualified=null,287721117)
2. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of ar.com.olx.api.rest.CuentaServiceRS errors were found
3. java.lang.IllegalStateException: Unable to perform operation: resolve on ar.com.olx.api.rest.CuentaServiceRS
我的 API 休息 class
@Path("/account")
public class CuentaServiceRS {
@Inject
private ICuentaService cuentaService;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Cuenta getCuenta() {
return cuentaService.getCuentas().get(0);
}
}
pom.xml
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.22.2</version>
</dependency>
web.xml
<servlet>
<servlet-name>altitudeservlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>ar.com.villat.bind.ApplicationJaxRS</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
我的应用程序 JAX-RS class
public class ApplicationJaxRS extends ResourceConfig {
public ApplicationJaxRS(){
register(new CustomBinder());
packages(true, "ar.com.villat");
}
}
最后,我的自定义活页夹
public class CustomBinder extends AbstractBinder {
@Override
protected void configure() {
bind(ICuentaService.class).to(CuentaServiceImpl.class);
}
}
如果您需要更多详细信息,请告诉我
在AbstractBinder
中,应该是bind(Implementation).to(Contract)
。你有相反的方式。他们这样做的原因是一个实现可能有多个合同,所以你可以只链接 to
调用。
从 :
更改 CustomBinder 实现@Override
protected void configure() {
bind(ICuentaService.class).to(CuentaServiceImpl.class);
}
到
@Override
protected void configure() {
bind(ICuentaService.class).to(CuentaServiceImpl.class);
}
应该适合你。
换句话说,我建议按照以下思路创建接口:
public interface ICuenta {
// define an API
Cuenta getCeunta();
}
然后在class中实现为
public class ICuentaService implements ICuenta {
// implement the API
Cuenta getCeunta() {
// get it form somewher and return;
}
}
并将它们绑定为
@Override
protected void configure() {
bind(ICuenta.class).to(ICuentaService.class);
}
并在您的资源 class 中进一步使用它作为:
ICuenta icuenta;
@Inject
public CuentaServiceRS(ICuenta icuenta) {
this.icuenta = icuenta;
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public Cuenta getCuenta() {
return icuenta.getCeunta();
}