hk2

Determine ServiceLocator has no user defined services

你说的曾经没有我的故事 提交于 2019-12-13 05:27:41
问题 I'm trying to make a reusable component that creates a ServiceLocator from the services defined in the inhabitants file. I need to determine if the ServiceLocator has services apart from the built in ones. If it doesn't, maybe log some warning to the user. Something like ServiceLocator locator = ServiceLocatorUtilities.createAndPopulateServiceLocator(); List<?> services = locator.getAllServices(BuilderHelper.allFilter()); if (services.isEmpty()) { LOGGER.log(Level.WARNING, "No services. Make

Writing HK2 components in GlassFish 4?

烈酒焚心 提交于 2019-12-13 04:42:00
问题 In version 3 there is this guide on how to write components(including HK2 components): Oracle GlassFish Server 3.0.1 Add-On Component Development Guide This documentation is not available with GF4. Why not? Why am I asking? Because I want to write a custom Logging Handler, as documented in Chapter 7 of the administration guide(https://glassfish.java.net/docs/4.0/administration-guide.pdf). "Note: The custom handler class should be packaged in an OSGi module and the JAR file placed in the as

WELD-001408: Unsatisfied dependencies for type in GlassFish + Jersey 2

六月ゝ 毕业季﹏ 提交于 2019-12-13 04:13:12
问题 I am trying to inject a class into my Jersey JAX-RS application using HK2, running on GlassFish. But when I try to run my application I get this error: com.sun.enterprise.admin.remote.RemoteFailureException: Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied

EnityManager Injection via HK2 in WebSockets

风格不统一 提交于 2019-12-13 03:12:53
问题 I have written 2 WebSocket ServerEndpoints that inject Services that themselves interact with the Database using injected instances of the JPA EntityManager. The application is a web application deployed on a Tomcat Server, using Jersey as JAX-RS implementation and Hibernate as JPA Provider. Sometimes it happens that the EntityManager is closed when trying to the DB inside the Endpoints. Also I fear I might have produced code that triggers a Memory Leak. This is the custom ServerEndpoint

How to inject an unbound generic type in HK2?

佐手、 提交于 2019-12-13 01:25:26
问题 I'm writing a webservice using Jersey 2.9 and I'm also using HK2 for DI. I have a class which handles a connection to a database which can be instantiated like that: public class DBHandler { private DBConnection<?> dbConnection; @Inject public DBHandler(DBConnection<?> dbConnection) { this.dbConnection = dbConnection; } } As you can see, field dbConnection has an unbounded generic type. By binding implementation currently looks like follows: public class MyProductionBinder extends

Exception when deploying on glassfish: ArrayIndexOutOfBoundsException: 9578

谁说胖子不能爱 提交于 2019-12-11 18:28:22
问题 when I deploy my war file on tomcat it is ok but when I deploy it on glassfish it gives the exception, I searched but found no result how to solve this. java.lang.ArrayIndexOutOfBoundsException: 9578 at org.objectweb.asm.ClassReader.readClass(Unknown Source) at org.objectweb.asm.ClassReader.accept(Unknown Source) at org.objectweb.asm.ClassReader.accept(Unknown Source) at org.glassfish.hk2.classmodel.reflect.Parser$5.on(Parser.java:363) at com.sun.enterprise.v3.server

How can I inject a custom factory using hk2?

青春壹個敷衍的年華 提交于 2019-12-11 11:01:42
问题 I'm having a hard time to work with jersey test framework. I have a root resource. @Path("sample") public class SampleResource { @GET @Path("path") @Produces({MediaType.TEXT_PLAIN}) public String readPath() { return String.valueOf(path); } @Inject private java.nio.file.Path path; } I prepared a factory providing the path . public class SamplePathFactory implements Factory<Path> { @Override public Path provide() { try { return Files.createTempDirectory(null); } catch (final IOException ioe) {

How to collect several interfaces into a Collection in HK2?

不羁的心 提交于 2019-12-11 10:13:16
问题 I have my AbstractBinder and I bind several classes with the same interface. Let's say I bind Fish and Cat which both implement Animal interface. What is the easiest/proper way of injecting them into a bean which takes Collection<Animal> ? PS: Spring has equivalent in simply @Autowire List<Animal> and the collection is created and populated by Spring. 回答1: HK2 has IterableProvider<T>, as mentioned here in the documentation. You can get the service by name, by qualifier annotation, or just

How can I bind a factory to a annotation-qualified injection point?

情到浓时终转凉″ 提交于 2019-12-11 03:06:15
问题 I asked and got an answer how to bind a named injection point. And I don't know how to bind a factory to a qualified injection point. class SomeResource { @Inject @Some // is a @Qualifier, of course. private MyType qualified; } I prepared a factory class SomeFactory extends Factory<MyType> { } And I stuck on creating a binder for that class SomeBinder extends AbstractBinder { @Override protected void configure() { // @@? } } I actually want to know how to use ServiceBindingBuilder#qualifiedBy

How do I define a “default” implementation in HK2?

萝らか妹 提交于 2019-12-10 23:59:49
问题 I am using HK2 to resolve dependencies of services in my Jersey / Jetty web service. I have a situation where for one particular interface, I want to use a specific implementation as a "default" implementation. By "default" I mean no names or qualifiers - it is what you get if you do not specify any annotations on top of the field or argument. However, in a few very specific situations, I want to provide an alternative implementation that will be qualified with an annotation. As a result of