probuje wczytac klasę ale dostaje to :
ktos wie o co chodzi? uruchamiam na tomcat ee
pre>javax.servlet.ServletException: A MultiException has 3 exceptions. They are:
- org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=InjectMe,parent=UserService,qualifiers={},position=-1,optional=false,self=false,unqualified=null,652298842)
- java.lang.IllegalArgumentException: While attempting to resolve the dependencies of com.github.sbahmani.rest.UserRest.UserService errors were found
- java.lang.IllegalStateException: Unable to perform operation: resolve on com.github.sbahmani.rest.UserRest.UserService
//import javax.enterprise.context.ApplicationScoped;
//
//@ApplicationScoped
public class InjectMe {
public void get () {
System.out.println("hello");
}
}
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@Path("/user")
public class UserService {
@Inject
private InjectMe injectMe;
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/users")
public Response getAll() {
try {
injectMe.get();
List<User> users = UserDAO.findAll();
return Response.status(Response.Status.OK).entity(users).build();
} catch(Exception e) {
return Response.status(Response.Status.BAD_REQUEST).entity(e).build();
}
}
}
fragment pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.12</junit.version>
<hibernate.version>5.3.6.Final</hibernate.version>
<hibernate.validator.version>6.0.13.Final</hibernate.validator.version>
<javax-el.version>3.0.1-b10</javax-el.version>
<maven-compiler-plugin-version>3.7.0</maven-compiler-plugin-version>
<jersey.version>2.27</jersey.version>
<servlet-api.version>4.0.1</servlet-api.version>
</properties>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>${javax-el.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.bundles</groupId>
<artifactId>jaxrs-ri</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>