Wso2 Jax-RS服务项目无法加载Wso2依赖项

时间:2017-09-05 11:08:34

标签: java web-services maven wso2 osgi

我正在使用Wso2 Development Studio开发一个Jax-RS服务项目。 我想使用其他类的其他Wso2模块。所以我尝试将项目中的那些作为maven依赖项包含在内。

然而,似乎我做错了,因为我无法使依赖工作。

例如我有这些依赖

 <dependencies>
    <dependency>
      <groupId>javax.ws.rs</groupId>
      <artifactId>jsr311-api</artifactId>
      <version>1.1.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.wso2.carbon</groupId>
      <artifactId>org.wso2.carbon.user.core</artifactId>
      <version>4.2.0</version>
    </dependency>
    <dependency>
      <groupId>org.wso2.carbon</groupId>
      <artifactId>org.wso2.carbon.core</artifactId>
      <version>4.2.0</version>
    </dependency>
    <dependency>
      <groupId>org.wso2.carbon</groupId>
      <artifactId>org.wso2.carbon.core.common</artifactId>
      <version>4.2.0</version>
    </dependency>
  </dependencies>

但是当我尝试使用这些包中的东西时,我得到了一个未找到的课程

import javax.naming.directory.DirContext;
import javax.ws.rs.*;
import org.wso2.carbon.user.core.UserStoreException;


@Path("/")
public class Users {

    @GET
    public String getUsers()
    {
        return "this is v0.0.1";
    }

    @POST
    @Consumes("application/json")
    public String createUser() throws UserStoreException
    {
        throw new UserStoreException("this is an erro message but it worked");
        return "creatd";
    }
}

在此示例中,甚至无法导入UserStoreException

这是我导入所需包的方式

<plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>3.3.0</version>
        <extensions>true</extensions>
        <configuration>
          <obrRepository>NONE</obrRepository>
          <instructions>
            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
            <Bundle-Name>${project.artifactId}</Bundle-Name>
            <Bundle-Version>0.0.1</Bundle-Version>
                        <Export-Package>
                            example.*
                        </Export-Package>
            <Import-Package>
                  org.wso2.carbon.*,
                  org.apache.commons.logging.*,
                  org.osgi.framework.*,
                  javax.naming.*,
                  org.osgi.service.component.*
           </Import-Package>
          </instructions>
        </configuration>
      </plugin> 

导入时出错了吗?

如何成功导入Wso2依赖项?

以下是服务器上的完整异常堆栈跟踪:

type Exception report

message Servlet.init() for servlet cxf threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception

    javax.servlet.ServletException: Servlet.init() for servlet cxf threw exception
        org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
        org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        org.wso2.carbon.identity.context.rewrite.valve.TenantContextRewriteValve.invoke(TenantContextRewriteValve.java:72)
        org.wso2.carbon.identity.authz.valve.AuthorizationValve.invoke(AuthorizationValve.java:91)
        org.wso2.carbon.identity.auth.valve.AuthenticationValve.invoke(AuthenticationValve.java:60)
        org.wso2.carbon.tomcat.ext.valves.CompositeValve.continueInvocation(CompositeValve.java:99)
        org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve$1.invoke(CarbonTomcatValve.java:47)
        org.wso2.carbon.webapp.mgt.TenantLazyLoaderValve.invoke(TenantLazyLoaderValve.java:57)
        org.wso2.carbon.tomcat.ext.valves.TomcatValveContainer.invokeValves(TomcatValveContainer.java:47)
        org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValve.java:62)
        org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.invoke(CarbonStuckThreadDetectionValve.java:159)
        org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958)
        org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(CarbonContextCreatorValve.java:57)
        org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
        org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
        org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
        org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1756)
        org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1715)
        java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        java.lang.Thread.run(Thread.java:748)
    root cause

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UsersBean' defined in URL [jndi:/localhost/wso2usersapi-0.0.1/WEB-INF/cxf-servlet.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/wso2/carbon/user/core/UserStoreException
        org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:526)
        org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
        org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
        org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
        org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
        org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
        org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
        org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
        org.apache.cxf.transport.servlet.CXFServlet.createSpringContext(CXFServlet.java:151)
        org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:74)
        org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:76)
        org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
        org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        org.wso2.carbon.identity.context.rewrite.valve.TenantContextRewriteValve.invoke(TenantContextRewriteValve.java:72)
        org.wso2.carbon.identity.authz.valve.AuthorizationValve.invoke(AuthorizationValve.java:91)
        org.wso2.carbon.identity.auth.valve.AuthenticationValve.invoke(AuthenticationValve.java:60)
        org.wso2.carbon.tomcat.ext.valves.CompositeValve.continueInvocation(CompositeValve.java:99)
        org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve$1.invoke(CarbonTomcatValve.java:47)
        org.wso2.carbon.webapp.mgt.TenantLazyLoaderValve.invoke(TenantLazyLoaderValve.java:57)
        org.wso2.carbon.tomcat.ext.valves.TomcatValveContainer.invokeValves(TomcatValveContainer.java:47)
        org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValve.java:62)
        org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.invoke(CarbonStuckThreadDetectionValve.java:159)
        org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958)
        org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(CarbonContextCreatorValve.java:57)
        org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
        org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
        org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
        org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1756)
        org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1715)
        java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        java.lang.Thread.run(Thread.java:748)
    root cause

    java.lang.NoClassDefFoundError: org/wso2/carbon/user/core/UserStoreException
        java.lang.Class.getDeclaredMethods0(Native Method)
        java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        java.lang.Class.getDeclaredMethods(Class.java:1975)
        org.apache.cxf.common.util.ReflectionUtil$6.run(ReflectionUtil.java:127)
        org.apache.cxf.common.util.ReflectionUtil$6.run(ReflectionUtil.java:125)
        java.security.AccessController.doPrivileged(Native Method)
        org.apache.cxf.common.util.ReflectionUtil.getDeclaredMethods(ReflectionUtil.java:125)
        org.apache.cxf.common.annotation.AnnotationProcessor.processMethods(AnnotationProcessor.java:85)
        org.apache.cxf.common.annotation.AnnotationProcessor.accept(AnnotationProcessor.java:72)
        org.apache.cxf.common.injection.ResourceInjector.inject(ResourceInjector.java:118)
        org.apache.cxf.common.injection.ResourceInjector.inject(ResourceInjector.java:112)
        org.apache.cxf.bus.spring.Jsr250BeanPostProcessor.postProcessBeforeInitialization(Jsr250BeanPostProcessor.java:136)
        org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:393)
        org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1415)
        org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:518)
        org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
        org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
        org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
        org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
        org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
        org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
        org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
        org.apache.cxf.transport.servlet.CXFServlet.createSpringContext(CXFServlet.java:151)
        org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:74)
        org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:76)
        org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
        org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        org.wso2.carbon.identity.context.rewrite.valve.TenantContextRewriteValve.invoke(TenantContextRewriteValve.java:72)
        org.wso2.carbon.identity.authz.valve.AuthorizationValve.invoke(AuthorizationValve.java:91)
        org.wso2.carbon.identity.auth.valve.AuthenticationValve.invoke(AuthenticationValve.java:60)
        org.wso2.carbon.tomcat.ext.valves.CompositeValve.continueInvocation(CompositeValve.java:99)
        org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve$1.invoke(CarbonTomcatValve.java:47)
        org.wso2.carbon.webapp.mgt.TenantLazyLoaderValve.invoke(TenantLazyLoaderValve.java:57)
        org.wso2.carbon.tomcat.ext.valves.TomcatValveContainer.invokeValves(TomcatValveContainer.java:47)
        org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValve.java:62)
        org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.invoke(CarbonStuckThreadDetectionValve.java:159)
        org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958)
        org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(CarbonContextCreatorValve.java:57)
        org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
        org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
        org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
        org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1756)
        org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1715)
        java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        java.lang.Thread.run(Thread.java:748)

1 个答案:

答案 0 :(得分:0)

由于wso2工件未与maven中心同步,因此在尝试构建项目时可能会出错。 您能否将以下存储库添加到您的pom.xml中并进行构建。

<repositories>
        <!-- WSO2 released artifact repository -->
        <repository>
            <id>wso2.releases</id>
            <name>WSO2 Releases Repository</name>
            <url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>daily</updatePolicy>
                <checksumPolicy>ignore</checksumPolicy>
            </releases>
        </repository>

        <!-- WSO2 Snapshot artifact repository -->
        <repository>
            <id>wso2.snapshots</id>
            <name>WSO2 Snapshot Repository</name>
            <url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>daily</updatePolicy>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>

        <repository>
            <id>wso2-nexus</id>
            <name>WSO2 internal Repository</name>
            <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>daily</updatePolicy>
                <checksumPolicy>ignore</checksumPolicy>
            </releases>
        </repository>
    </repositories>