小编Vik*_*lva的帖子

jersey 2.0 :: for cdi注入,bean.xml是强制性的吗?

资源类

public class UploadFileService {

    @Inject public Logger logger;

    @POST
    @Path("/upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadFile(
        @FormDataParam("file") InputStream uploadedInputStream,
        @FormDataParam("file") FormDataContentDisposition fileDetail) {
    }
}
Run Code Online (Sandbox Code Playgroud)

注入:: Logger类

@Dependent
public final class Loggers {

    @Produces
    public static final Logger getLogger(final InjectionPoint injectionPoint) {
    if (injectionPoint == null) {
        throw new IllegalArgumentException("injectionPoint", new NullPointerException("injectionPoint"));
    }
}
Run Code Online (Sandbox Code Playgroud)

注入完美适用于包含beans.xml

*的.war\WEB-INF \类\ META-INF\beans.xml中

但是它不是在泽西2.0中可选的beans.xml吗?

缺少beans.xml时报告错误

org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=Logger,parent=UploadFileService,
qualifiers={},position=-1,optional=false,self=false,unqualified=null,1642832267)
        at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:74)
        at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:947)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:902)
        at org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider$CdiFactory$2.getInstance(CdiComponentProvider.java:245)
        at org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider$CdiFactory.provide(CdiComponentProvider.java:189) …
Run Code Online (Sandbox Code Playgroud)

java cdi jersey-2.0

6
推荐指数
2
解决办法
1548
查看次数

标签 统计

cdi ×1

java ×1

jersey-2.0 ×1