2016-12-30 39 views
0

當我嘗試一個似鯖水狼牙魚4.1.1服務器上部署的JavaEE我7戰項目出現以下錯誤:WELD-001408嘗試部署其他項目作爲引用一個JAR項目使用JPA內容戰類型時

部署期間發生錯誤:加載應用程序時發生異常:CDI部署失敗:WELD-001408:類型爲RatingEJB的不滿意依賴關係帶限定符@Default在注入點[BackedAnnotatedField] @Inject private rest.resources.RatingResource.persistenceBean at rest.resources。 RatingResource.persistenceBean(RatingResource.java:0)。

的stracktrace如下:

org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type RatingEJB with qualifiers @Default 
at injection point [BackedAnnotatedField] @Inject private rest.resources.RatingResource.persistenceBean 
at rest.resources.RatingResource.persistenceBean(RatingResource.java:0) 
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:355) 
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:277) 
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:130) 
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:151) 
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:494) 
at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:480) 
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:455) 
at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:454) 
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:90) 
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:226) 
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:131) 
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:329) 
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:497) 
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:220) 
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:487) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535) 
at java.security.AccessController.doPrivileged(Native Method) 
at javax.security.auth.Subject.doAs(Subject.java:356) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557) 
at java.security.AccessController.doPrivileged(Native Method) 
at javax.security.auth.Subject.doAs(Subject.java:356) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722) 
at org.glassfish.admin.rest.utils.ResourceUtil.runCommand(ResourceUtil.java:263) 
at org.glassfish.admin.rest.utils.ResourceUtil.runCommand(ResourceUtil.java:234) 
at org.glassfish.admin.rest.utils.ResourceUtil.runCommand(ResourceUtil.java:285) 
at org.glassfish.admin.rest.resources.TemplateListOfResource.createResource(TemplateListOfResource.java:136) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:606) 
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) 
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) 
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) 
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160) 
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) 
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) 
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) 
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) 
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326) 
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:317) 
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) 
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) 
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:384) 
at org.glassfish.admin.rest.adapter.RestAdapter$2.service(RestAdapter.java:316) 
at org.glassfish.admin.rest.adapter.RestAdapter.service(RestAdapter.java:179) 
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:466) 
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:169) 
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206) 
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180) 
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) 
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) 
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) 
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:526) 
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) 
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) 
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) 
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) 
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593) 
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573) 
at java.lang.Thread.run(Thread.java:745) 

這裏是我的項目結構

project structue 1

project structue 2

這是從戰爭中項目資源類:

package rest.resources; 

import java.util.ArrayList; 
import java.util.Iterator; 
import java.util.List; 

import javax.ejb.Stateless; 
import javax.inject.Inject; 
import javax.ws.rs.Path; 
import javax.ws.rs.core.Context; 
import javax.ws.rs.core.Response; 
import javax.ws.rs.core.UriInfo; 

import persistance.ejb.RatingEJB; 
import persistance.entities.Personalization; 
import persistance.entities.Rating; 
import rest.domain.RatingCollection; 
import rest.domain.RatingDetails; 
import rest.factory.RatingCollectionFactory; 

@Stateless 
@Path("/ratings") 
public class RatingResource implements IRatingResource 
{ 
@Context 
private UriInfo uriInfo; 

@Inject 
private RatingEJB persistenceBean; 

@Inject 
private RatingDetailsFactory detailsFactory; 
@Inject 
private RatingCollectionFactory CollectionFactory; 

@Override 
public Response get(int start, int size) 
{ 
    RatingCollection collection = null; 

    List<RatingDetails> details = new ArrayList<>(); 
    List<Rating> list = persistenceBean.findAll(start, size); 

    if (list != null) 
    { 
     Iterator<Rating> iterator = list.iterator(); 
     while (iterator.hasNext()) 
     { 
      Rating rating = iterator.next(); 
      RatingDetails ratingDetails = detailsFactory.createDetail(uriInfo, persistenceBean.create(rating), rating.getId()); 

      details.add(ratingDetails); 
     } 
     collection = CollectionFactory.createCollection(details, uriInfo, size, start); 
    } 

    return Response.ok(collection).build(); 
} 

} 

下面是從罐子EJB類

package persistance.ejb; 

import java.util.List; 

import javax.ejb.Stateless; 
import javax.persistence.EntityManager; 
import javax.persistence.PersistenceContext; 
import javax.persistence.TypedQuery; 

import persistance.entities.Rating; 

@Stateless 
public class RatingEJB implements IPersistanceBean<Rating> 
{ 
@PersistenceContext(unitName = "feedback") 
private EntityManager em; 

@Override 
public Rating find(Object id) 
{ 
    return em.find(Rating.class, id); 
} 

@Override 
public List<Rating> findAll(int start, int size) 
{ 
    TypedQuery<Rating> query = em.createQuery("SELECT r FROM Rating r", Rating.class); 
    query.setFirstResult(start).setMaxResults(size); 

    return query.getResultList(); 
} 

@Override 
public Rating create(Rating rating) 
{ 
    em.persist(rating); 

    return rating; 
} 

@Override 
public void remove(Object id) 
{ 
    em.remove(em.find(Rating.class, id)); 
} 

@Override 
public Rating update(Rating item) 
{ 
    // TODO Auto-generated method stub 
    return null; 
} 
} 

這裏是項目的勁歌

父:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>feedback</groupId> 
<artifactId>feedback-parent</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>pom</packaging> 
<name>feedback-parent</name> 
<modules> 
    <module>feedback-persistance</module> 
    <module>feedback-rest</module> 
</modules> 

<properties> 
    <version.java>1.7</version.java> 
    <version.maven.clean.plugin>2.4.1</version.maven.clean.plugin> 
    <version.maven.war.plugin>2.4</version.maven.war.plugin> 
    <version.maven.compiler.plugin>3.1</version.maven.compiler.plugin> 
    <version.maven.exec.plugin>1.2.1</version.maven.exec.plugin> 
    <javaee.api.version>7.0</javaee.api.version> 
</properties> 

<dependencies> 
    <!-- Java EE --> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-api</artifactId> 
     <version>${javaee.api.version}</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>rest</groupId> 
     <artifactId>rest-api</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
    </dependency> 

</dependencies> 

<build> 
    <finalName>feedback</finalName> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-clean-plugin</artifactId> 
       <version>${version.maven.clean.plugin}</version> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>${version.maven.compiler.plugin}</version> 
       <inherited>true</inherited> 
       <configuration> 
        <source>${version.java}</source> 
        <target>${version.java}</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>${version.maven.war.plugin}</version> 
       <configuration> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

反饋psersistance:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<parent> 
    <groupId>feedback</groupId> 
    <artifactId>feedback-parent</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
</parent> 
<artifactId>feedback-persistance</artifactId> 
<name>feedback-persistance</name> 

<build> 
    <finalName>feedback-persistance</finalName> 
</build> 

和反饋休息

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<parent> 
    <groupId>feedback</groupId> 
    <artifactId>feedback-parent</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
</parent> 
<artifactId>feedback-rest</artifactId> 
<packaging>war</packaging> 
<name>feedback-rest</name> 

<dependencies> 
    <dependency> 
     <groupId>rest</groupId> 
     <artifactId>rest-api</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
    </dependency> 

    <dependency> 
     <groupId>feedback</groupId> 
     <artifactId>feedback-persistance</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
     <scope>system</scope> 
     <systemPath>C:\Users\user\workspace_neon\feedback-parent\feedback-persistance\target\feedback-persistance.jar</systemPath> 
    </dependency> 
</dependencies> 

<build> 
    <finalName>feedback-rest</finalName> 
</build> 

那麼,什麼是錯的我的執行?我是JavaEE的新手,我在網上找到的所有內容都無效。

在此先感謝。 Rudi

回答

0

我能解決我的問題。解決方案是創建一個包含罐子和戰爭項目的耳項目。現在我可以在payara服務器上部署ear項目並從我的休息服務中查詢數據庫。

這裏是耳朵項目

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<parent> 
    <groupId>feedback</groupId> 
    <artifactId>feedback-parent</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
</parent> 
<artifactId>feedback-ear</artifactId> 
<packaging>ear</packaging> 
<name>feedback-ear</name> 

<dependencies> 
    <dependency> 
     <groupId>${project.groupId}</groupId> 
     <artifactId>feedback-persistance</artifactId> 
     <version>${project.version}</version> 
     <type>ejb</type> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>${project.groupId}</groupId> 
     <artifactId>feedback-rest</artifactId> 
     <version>${project.version}</version> 
     <type>war</type> 
    </dependency> 
</dependencies> 

<build> 
    <finalName>${project.artifactId}</finalName> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-ear-plugin</artifactId> 
      <version>2.10.1</version> 
      <configuration> 
       <version>7</version> 
       <defaultLibBundleDir>lib</defaultLibBundleDir> 
       <skinnyWars>true</skinnyWars> 
       <modules> 
        <webModule> 
         <groupId>${project.groupId}</groupId> 
         <artifactId>feedback-rest</artifactId> 
        </webModule> 
        <ejbModule> 
         <groupId>${project.groupId}</groupId> 
         <artifactId>feedback-persistance</artifactId> 
        </ejbModule> 
       </modules> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

+1

的POM這是沒有必要捆綁您的應用程序作爲EAR解決您的問題。我想這個maven並沒有將REST項目捆綁到WAR項目中,放到'WEB-INF/lib'中。嘗試刪除'系統'和' ...',因爲它沒有意義使用它。默認值更加標準,甚至可能需要maven將ejb-jar包裝到WAR中。 – OndrejM

+0

'系統'是必要的,因爲此刻我沒有訪問遠程回購。沒有耳朵包裝,持久性類對Web項目不可見。正如我所說,我是JavaEE的新手,但只是刪除耳朵包裝並不能解決我的問題... – rudi

+0

'系統'的替代方法是將[artefact]部署到[您的本地maven存儲庫](https ://maven.apache.org/plugins/maven-install-plugin/examples/specific-local-repo.html)。然後您不必更改pom.xml定義。我想知道,如果這有幫助。 – OndrejM

相關問題