hk2

Trouble creating a simple singleton class in Jersey 2 using built-in Jersey dependency injection

ぐ巨炮叔叔 提交于 2020-05-09 21:40:53
问题 I am having trouble getting a very basic implementation of a singleton class off the ground with Jersey 2 (2.7) and only Jersey's built-in HK2 dependency injection. I am running this on Tomcat. My goal is to create a singleton instance of a support class that will be used by various web service methods. I don't have a strong preference between constructor injection, method injection, and annotating a class member (as I do below). Here is my to-be-singleton class: package singletest; import

Trouble creating a simple singleton class in Jersey 2 using built-in Jersey dependency injection

爱⌒轻易说出口 提交于 2020-05-09 21:40:19
问题 I am having trouble getting a very basic implementation of a singleton class off the ground with Jersey 2 (2.7) and only Jersey's built-in HK2 dependency injection. I am running this on Tomcat. My goal is to create a singleton instance of a support class that will be used by various web service methods. I don't have a strong preference between constructor injection, method injection, and annotating a class member (as I do below). Here is my to-be-singleton class: package singletest; import

又见删库...

 ̄綄美尐妖づ 提交于 2020-02-27 00:26:35
这两天,香港上市公司微盟(HK2013)因"删库"事件停运,已经过了36小时还在努力抢修数据的工作中。作为一位老DBA,我们一起来回顾和尝试反思下这个事件。 0. 事件回顾 2020.2.23日 18:56,员工通过VPN登入服务器并实施破坏。 2020.2.23日 19时,系统监控报告故障并启动应急方案。 2020.2.24日 微盟公司向警方报案。 2020.2.25日 7时,恢复部分生产环境和数据,并预计到凌晨0点能完成恢复,并向新用户恢复业务,但老用户预计还要到2月28日晚上才能恢复。 1. 为什么会发生"删库" 从官方发布的公告来看,是因为运维部的核心员工刻意进行的破坏,也就是说,这是人为的、恶意的、有计划的破坏行为,而不是我们最常见的误操作或黑客入侵所致。 不过,从我的经验来看,这起事件未必是真的人为破坏,具体分析就不贴了。总之,我对官方的公告存疑。不过也不能改变人为破坏这个事实,就看公安机关怎么定性了。 我们要做的是,进行反思和预防此类事件一再发生,这也是本文的用意。 此外这种意外事故受害的除了公司、员工,更无辜的是客户,我们祝福微盟能救回更多数据,将损失最小化。 2. 事故恢复的速度如何 从上面的回顾时间点来看,我认为恢复的速度并不算快。 我经过侧面了解,这起事件主要的影响是数据库的主备库都被删了,并且执行的是类似"rm -fr /"这样的操作。这种行为

Jersey 2 + HK2 - @ApplicationScoped not working

痴心易碎 提交于 2020-01-15 03:33:08
问题 I have class @ApplicationScoped public class Service{ private Map<String, Integer> something ; private final Logger LOGGER = LoggerFactory.getLogger(Service.class); @PostConstruct public void initialize(){ something = new HashMap<>(); } public void increase(String userName){ something.put(userName, something.getOrDefault(userName, 0) + 1); } public Map<String, Integer> getSomething(){ return this.something; } public Integer getSomethingForUser(String userName){ return something.getOrDefault

Swagger HK2 service reification failed

瘦欲@ 提交于 2020-01-14 07:46:08
问题 This application use Swagger (swagger-jersey2-jaxrs, 1.5.18), Spring-boot (spring-boot-starter-jersey, 2.0.1.RELEASE) and Java 9. When application ran Swagger UI loads without an issue. But I can see following warning in the logs. Appreciate any idea to solve this. I have tried upgrading versions but couldn't help. 2018-04-17 14:27:19.792 WARN 24810 --- [nio-7070-exec-5] org.glassfish.jersey.internal.Errors : The following warnings have been detected: WARNING: HK2 service reification failed

SpringBoot之java.lang.NoClassDefFoundError

寵の児 提交于 2020-01-07 15:18:15
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 一、预备 首先确认你的确有下载到依赖,不然的话这个问题很明确就是要你去找到正确的依赖 我项目的pom文件明明就依赖了这个类所在的文件了,为什么还报类未定义异常呢?而且在idea下查找类也能明确看到类也在maven的外部依赖中看到了,如下以下面的异常为例,看到的确在maven中找到了。执行run Application确还是报错。 Exception in thread "main" java.lang.NoClassDefFoundError: org/glassfish/hk2/utilities/reflection/ReflectionHelper 二、定位问题 经过如上确认后,可以想到应该是配置出了问题了 可以看到这个启动类依赖的classpath是模块的类路径,并且启动的是Application并不是Maven应用,看这个模块的报类未定义的错引入类是hk2-utils是provided的, 再看启动打印的启动信息如下: C:\Java\jdk1.8.0_101\bin\java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:49736,suspend=y,server=n -classpath C:\Users\cqq\AppData

Inject not working for nested objects[Jersey 2.22.1]

巧了我就是萌 提交于 2019-12-29 08:14:09
问题 I have a Jersey resource with a facade object injected. This is configured in my ResourceConfig and the facade gets injected fine. The facade contains a DAO class which also should be injected and is configured in the same ResourceConfig . Now to my problem; the DAO class is null. Thus, not injected. @ApplicationPath("/service") public class SystemSetup extends ResourceConfig { public SystemSetup() { packages(false, "com.foo.bar"); packages("org.glassfish.jersey.jackson"); register

Inject not working for nested objects[Jersey 2.22.1]

爷,独闯天下 提交于 2019-12-29 08:14:08
问题 I have a Jersey resource with a facade object injected. This is configured in my ResourceConfig and the facade gets injected fine. The facade contains a DAO class which also should be injected and is configured in the same ResourceConfig . Now to my problem; the DAO class is null. Thus, not injected. @ApplicationPath("/service") public class SystemSetup extends ResourceConfig { public SystemSetup() { packages(false, "com.foo.bar"); packages("org.glassfish.jersey.jackson"); register

How does ServiceLocator find @Service and @Contact automatically in HK2?

♀尐吖头ヾ 提交于 2019-12-28 23:59:07
问题 According to HK2 @Service javadoc Annotation placed on classes that are to be automatically added to an hk2 ServiceLocator. I don't know how to make ServiceLocator find annotated classes automatically. TestService @Contract public interface TestService { } TestServiceImpl @Service public class TestServiceImpl implements TestService { } Main public static void main(String[] args) { ServiceLocator locator = ServiceLocatorUtilities.createAndPopulateServiceLocator(); TestService service = locator

HK2 MethodInterceptor with Jersey resource

半城伤御伤魂 提交于 2019-12-23 10:34:17
问题 How can I set up an aop MethodInterceptor to work with Jersey resources? Here is what I've tried, following this documentation: Step 1 - InterceptionService public class MyInterceptionService implements InterceptionService { private final Provider<AuthFilter> authFilterProvider; @Inject public HK2MethodInterceptionService(Provider<AuthFilter> authFilterProvider) { this.authFilterProvider = authFilterProvider; } /** * Match any class. */ @Override public Filter getDescriptorFilter() { return