将Spring组件注入Jersey 2.22.1

时间:2016-01-25 22:34:19

标签: spring spring-boot jersey-2.0 weblogic12c spring-web

使用的技术: Spring Boot 4.2.4-RELEASE Jersey 2.x(春季靴子入门版) 部署在Weblogic 12.1.3上

我遇到了org.glassfish.hk2.api.UnsatisfiedDependencyException:当我尝试注入Spring托管资源时,Injectee错误中没有可用于注入的对象。

的pom.xml

<parent>
    <artifactId>sl-locates-ui-appsrv</artifactId>
    <groupId>com.db.sl</groupId>
    <version>0.0.0-SNAPSHOT</version>
</parent>

<properties>
    <start-class>com.db.sl.config.Application</start-class>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>


    <!-- Phoenix Specific -->
    <dependency>
        <groupId>com.db.sl</groupId>
        <artifactId>sl-locates-ftp-core</artifactId>
        <version>${sl-locates-ftp-core.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>servlet-api</artifactId>
                <groupId>javax.servlet</groupId>
            </exclusion>
        </exclusions>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.db.gef</groupId>
        <artifactId>SLUtils</artifactId>
        <version>${slutils.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.sybase</groupId>
        <artifactId>jconn4</artifactId>
        <version>${jconn4.version}</version>
        <type>jar</type>
        <scope>provided</scope>
    </dependency>

    <!-- Spring -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
    </dependency>

</dependencies>

weblogic.xml中

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.3</wls:weblogic-version>
<wls:library-ref>
    <library-name>jax-rs</library-name>
    <specification-version>2.0</specification-version>
    <exact-match>false</exact-match>
</wls:library-ref>

<wls:container-descriptor>
    <wls:prefer-application-packages>
        <wls:package-name>org.apache.log4j.*</wls:package-name>
        <wls:package-name>org.slf4j</wls:package-name>
    </wls:prefer-application-packages>
</wls:container-descriptor>

这是我的SpringBootApplication类

@SpringBootApplication
public class Application extends SpringBootServletInitializer implements WebApplicationInitializer {

public static void main(String[] args) throws Exception {
    SpringApplication.run(Application.class, args);
}

/*protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return builder.sources(Application.class, SpringConfiguration.class);
}*/

@Bean
public ServletContainer jerseyServlet() {
    return new ServletContainer();
}

@Bean
public ServletRegistrationBean jerseyServletRegistration() {
    ServletRegistrationBean registration = new ServletRegistrationBean(jerseyServlet());
    Map<String,String> params = new HashMap<String,String>();
    params.put("contextClass","org.springframework.web.context.support.AnnotationConfigWebApplicationContext");
    params.put("contextConfigLocation", "com.db.sl.config.SpringConfiguration");
    registration.setInitParameters(params);
    return registration;
}
}

泽西岛的配置类

@Named
@ApplicationPath("/rest")
public class JerseyConfig extends ResourceConfig {
    public JerseyConfig() {
        packages(true, "com.db.sl");
        register(LocatesRestEndPoint.class);
    }
}

Spring的配置类

@Configuration
@EnableAutoConfiguration
@ComponentScan("com.db.sl")
public class SpringConfiguration {

@Bean
@Inject
LocatesDAO createLoactesDAO(DataSource dataSource) {
    System.out.println("DataSource: " + dataSource.toString());
    return new LocatesDAOImpl(dataSource);
}
}

最后发生错误的类

@Named
@Path("/locates")
public class LocatesRestEndPoint {

@Inject
private LocatesRequestService requestsService;

@GET
@Path("/requests/{customerKey}")
@Produces(MediaType.APPLICATION_JSON)
public LocatesWebResponse getFileRequestsWith(@PathParam("customerId") String customerId) throws Exception {
    log.info("Facilitating request for Locates File Requests with customer key " + customerId);

    return requestsService.getLocateRequests(customerId);
}
}

我一直在将此项目部署到tomcat上,但我们的工作环境需要使用weblogic。该项目适用于tomcat但在weblogic上我甚至没有在部署时显示spring横幅。我已经检查了所有可以找到的日志,但没有发现其他错误情况。我所拥有的堆栈跟踪是:

####<Jan 25, 2016 5:09:25 PM EST> <Error> <HTTP> <USRDUDT808849>     <AdminServer> <[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1453759765485> <BEA-101017> <[ServletContext@2070365887[app:sl-locates-ui-appsrv-rest-0.0.0-SNAPSHOT module:sl-locates-ui-appsrv-rest-0.0.0-SNAPSHOT.war path:null spec-version:3.0], request: weblogic.servlet.internal.ServletRequestImpl@15ba67aa[
GET /sl-locates-ui-appsrv-rest-0.0.0-SNAPSHOT/rest/locates/requests/with-date/2010-02-03 HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
DNT: 1
Connection: Keep-Alive

]] Root cause of ServletException.
A MultiException has 3 exceptions.  They are:
1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at Injectee(requiredType=LocatesRequestService,parent=LocatesRestEndPoint,qualifiers={}),position=-1,optional=false,self=false,unqualified=null,1669020655)
2. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of com.db.sl.appsrv.endpoints.LocatesRestEndPoint errors were found
3. java.lang.IllegalStateException: Unable to perform operation: resolve on com.db.sl.appsrv.endpoints.LocatesRestEndPoint

at org.jvnet.hk2.internal.Collector.throwIfErrors(Collector.java:88)
at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:269)
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:413)
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:456)
at org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:158)
at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2488)
at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:629)
at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:614)
at org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:173)
at org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.getInstance(MethodHandler.java:185)
at org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:103)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:128)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:131)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:131)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:131)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:131)
at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:110)
at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:65)
at org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:250)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:318)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1010)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:373)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:382)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:345)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:220)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:243)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3432)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)

引起:org.glassfish.hk2.api.UnsatisfiedDependencyException:Injectee没有可用于注入的对象(r​​equiredType = LocatesRequestService,parent = LocatesRestEndPoint,qualifiers = {}),position = -1,optional = false,self =假,不合格= NULL,1669020655)     在org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:74)     在org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:231)     在org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:254)     在org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:413)     at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:456)     在org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:158)     at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2488)     at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:629)     at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:614)     在org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:173)     at org.glassfish.jersey.server.model.MethodHandler $ ClassBasedMethodHandler.getInstance(MethodHandler.java:185)     在org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:103)     在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:128)     在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:131)     在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:131)     在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:131)     在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:131)     在org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:110)     在org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:65)     在org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)     在org.glassfish.jersey.server.ServerRuntime $ 1.run(ServerRuntime.java:250)     在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:271)     在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:267)     在org.glassfish.jersey.internal.Errors.process(Errors.java:315)     在org.glassfish.jersey.internal.Errors.process(Errors.java:297)     在org.glassfish.jersey.internal.Errors.process(Errors.java:267)     在org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:318)     在org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)     在org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1010)     在org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:373)     在org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:382)     在org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:345)     在org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:220)     在weblogic.servlet.internal.StubSecurityHelper $ ServletServiceAction.run(StubSecurityHelper.java:280)     在weblogic.servlet.internal.StubSecurityHelper $ ServletServiceAction.run(StubSecurityHelper.java:254)     在weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)     在weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346)     在weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:243)     at weblogic.servlet.internal.WebAppServletContext $ ServletInvocationAction.wrapRun(WebAppServletContext.java:3432)     at weblogic.servlet.internal.WebAppServletContext $ ServletInvocationAction.run(WebAppServletContext.java:3402)     在weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)     在weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)     在weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)     在weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285)     在weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201)     在weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)     在weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572)     在weblogic.servlet.provider.ContainerSupportProviderImpl $ WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)     在weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)     在weblogic.work.ExecuteThread.run(ExecuteThread.java:263)

  

0 个答案:

没有答案