When I try to deploy my JavaEE 7 war project on a payara 4.1.1 server the following error occurs:
Error occurred during deployment: Exception while loading the app : CDI deployment failure: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) .
The stracktrace is as follows:
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)
Here is my project structure
This is the resource class from the war project:
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();
}
}
Here is the ejb class from the jar
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;
}
}
And here are the poms of the projects
parent:
<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>
feedback-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>
and feedback-rest
<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>
So, what is wrong with my implementation? I'm new to JavaEE and everything I found on the web didn't work.
Thanks in advance. Rudi
I was able to solve my problem. The solution was to create an ear project that includes the jar and the war project. Now I can deploy the ear project at the payara server and query the database from my rest services.
Here is the pom of the ear project