gpt4 book ai didi

java - SSE实现(Weblogic 12.2.1.2.0 + Jax-RS 2.1(用于注册资源)+ CXF 3.2.5+ + Springboot + jersey 2.25.1)

转载 作者:太空宇宙 更新时间:2023-11-04 10:01:05 24 4
gpt4 key购买 nike

尝试使用上述技术实现 SSE,但微服务部署失败 -

Resource - 
@Path("/status-management")
public interface ISocketResource {
@GET
@Path("/v1/statusSocket")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void stockEvents(
@QueryParam("entityProcessContexts") List<String> entityProcessContexts,
@Context Sse sse,
@Context SseEventSink sseEventSink);
}

CXF 服务器注册 -

@Bean
public Server cxfServer() {
List<Object> serviceBeans = new ArrayList<Object>(ctx.getBeansWithAnnotation(Path.class).values());

List<Object> providers = new ArrayList<Object>(ctx.getBeansWithAnnotation(Provider.class).values());
providers.add(new FormEncodingProvider<Object>());
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setBus(ctx.getBean(SpringBus.class));
factory.setServiceBeans(serviceBeans);
factory.setProviders(providers);
factory.setFeatures(Arrays.asList(new SseFeature()));// registering SseFeature
Server server = factory.create();
return server;
}

异常 - 当 jersey 尝试加载 ext @Provider 类 - CXF 包的 OutboundSseEventBodyWriter 时失败。

OutboundSseEventBodyWriter 类有一个 protected 构造函数,不会导致问题。

    WARNING: HK2 service reification failed for [org.apache.cxf.jaxrs.sse.OutboundSseEventBodyWriter] with an exception:
MultiException stack 1 of 2
java.lang.NoSuchMethodException: Could not find a suitable constructor in org.apache.cxf.jaxrs.sse.OutboundSseEventBodyWriter class.
at org.glassfish.jersey.inject.hk2.JerseyClassAnalyzer.getConstructor(JerseyClassAnalyzer.java:192)
at org.jvnet.hk2.internal.Utilities.getConstructor(Utilities.java:180)
at org.jvnet.hk2.internal.ClazzCreator.initialize(ClazzCreator.java:129)
at org.jvnet.hk2.internal.ClazzCreator.initialize(ClazzCreator.java:180)
at org.jvnet.hk2.internal.SystemDescriptor.internalReify(SystemDescriptor.java:740)
at org.jvnet.hk2.internal.SystemDescriptor.reify(SystemDescriptor.java:694)
at org.jvnet.hk2.internal.ServiceLocatorImpl.reifyDescriptor(ServiceLocatorImpl.java:464)
at org.jvnet.hk2.internal.ServiceLocatorImpl.narrow(ServiceLocatorImpl.java:2310)
at org.jvnet.hk2.internal.ServiceLocatorImpl.access$1200(ServiceLocatorImpl.java:128)
at org.jvnet.hk2.internal.ServiceLocatorImpl$9.compute(ServiceLocatorImpl.java:1395)
at org.jvnet.hk2.internal.ServiceLocatorImpl$9.compute(ServiceLocatorImpl.java:1390)
at org.glassfish.hk2.utilities.cache.internal.WeakCARCacheImpl.compute(WeakCARCacheImpl.java:128)
at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetAllServiceHandles(ServiceLocatorImpl.java:1452)
at org.jvnet.hk2.internal.ServiceLocatorImpl.getAllServiceHandles(ServiceLocatorImpl.java:1377)
at org.jvnet.hk2.internal.ServiceLocatorImpl.getAllServiceHandles(ServiceLocatorImpl.java:1366)
....
.
.
.
.
.
MultiException stack 2 of 2
java.lang.IllegalArgumentException: Errors were discovered while reifying SystemDescriptor(
implementation=org.apache.cxf.jaxrs.sse.OutboundSseEventBodyWriter
contracts={javax.ws.rs.ext.MessageBodyWriter}
scope=javax.inject.Singleton
qualifiers={org.glassfish.jersey.internal.inject.Custom}
descriptorType=CLASS
descriptorVisibility=NORMAL
metadata=
rank=0
loader=null
proxiable=null
proxyForSameScope=null
analysisName=null
id=189
locatorId=0
identityHashCode=1355595726
reified=false)
at org.jvnet.hk2.internal.SystemDescriptor.reify(SystemDescriptor.java:705)
at org.jvnet.hk2.internal.ServiceLocatorImpl.reifyDescriptor(ServiceLocatorImpl.java:464)
at org.jvnet.hk2.internal.ServiceLocatorImpl.narrow(ServiceLocatorImpl.java:2310)
at org.jvnet.hk2.internal.ServiceLocatorImpl.access$1200(ServiceLocatorImpl.java:128)
at org.jvnet.hk2.internal.ServiceLocatorImpl$9.compute(ServiceLocatorImpl.java:1395)
at org.jvnet.hk2.internal.ServiceLocatorImpl$9.compute(ServiceLocatorImpl.java:1390)
.
.
.
.

<Nov 20, 2018, 11:19:17,989 AM IST> <Error> <HTTP> <BEA-101216> <Servlet: "JAX-RS/Jersey#1" failed to preload on startup in Web application: "/businessstatus-ms".
A MultiException has 2 exceptions. They are:
1. java.lang.InstantiationException
2. java.lang.IllegalStateException: Unable to perform operation: create on org.apache.cxf.jaxrs.provider.AbstractResponseViewProvider

at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:392)
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:487)
at org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:83)
at org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:71)
at org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture$1.call(Cache.java:97)
Truncated. see log file for complete stacktrace
Caused By: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1375)
at org.jvnet.hk2.internal.ClazzCreator.createMe(ClazzCreator.java:272)
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:366)
Truncated. see log file for complete stacktrace

最佳答案

在此处查看有关如何在 WebLogic 上使用 Apache CXF 的建议: http://cxf.apache.org/docs/jax-rs-deployment.html查看 WebLogic 部分。

关于java - SSE实现(Weblogic 12.2.1.2.0 + Jax-RS 2.1(用于注册资源)+ CXF 3.2.5+ + Springboot + jersey 2.25.1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53480167/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com