Hazelcast throwing exception in spring boot application with vaadin 8 using openfeign - spring-boot

We have a web application with Vaadin 8, Spring Boot 2.1.3 and Open Feign.
Now Hazelcast should be integrated for session replication.
I was following this article.
The Problem: with Open Feign an exception is thrown in the InvocationHandler: NotSerializableException, so I implemented my own InvocationHandlerFactory setting my own InvocationHandler that is implementing the Serializable interface.
Now in the InvocationHandler the same exception is thrown:
com.hazelcast.nio.serialization.HazelcastSerializationException: Failed to serialize 'org.springframework.session.MapSession'**
com.hazelcast.nio.serialization.HazelcastSerializationException: Failed to serialize 'org.springframework.session.MapSession'
Caused by: java.io.NotSerializableException: java.lang.reflect.Method
The problem is: java.io.NotSerializableException: java.lang.reflect.Method
Method is final so it cannot be made serializable.
Is there a way to tell Hazelcast not to try to serialize certain classes?
Any workaround?
I already tried to use the ApplicationContext to avoid serialization of open feign classes but it´s not possible because the open feign clients need to be session scoped.

You are probably injecting a Feign client in a UI component, right? If so, the same happened to me when I implemented that example and I solved it by creating the Services class you can see in the article. Instead of directly injecting beans that are Feign clients or that have references to them, you can call the static methods in the Services class.

Related

Spring Batch Bean Scope to convert Legacy Application

We have a legacy normal java application with below architectural flow
Facade ----> Corba remote IIOP Connection --> ServiceCommands
Above architecture we wants to convert as SpringBeans(Spring Boot) and call from MVCController and expose as RESTAPI
MVCController ---> Facade -->Corba Connection -->ServiceCommands
Please advise what is the Bean scope to be used for each layer and best architecture to be followed
Facade class Bean - Scope value="session"
CorbaConnection Class bean Scope value="session"
ServiceClass bean Scope value="singleton"
We have solved the issue by created a Corba connection Pool and make each connection from the pool is a Spring bean with scope "Session". Every session request to corba will be in Proxy mode and commit when the #service finishes. All the properties of pools has been added to maintain idle time and re-connection and return back to the pool after the service finishes. Service and Facade remains singleton bean. Thanks team for the support again to provide idea hints from your experiences.

Spring Boot + Spring Integration Java DSL + AOP : Fails to proxy the Gateway interface

Hi I have a spring boot application, which starts a spring integration flow, through a gateway interface, using Java DSL. Everything works fine on its own. I added AOP to capture exceptions, with #EnableAspectJAutoProxy(proxyTargetClass = true)
At this stage, it gives the error:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'jobInitiator': Post-processing of
FactoryBean's singleton object failed; nested exception is
org.springframework.aop.framework.AopConfigException: Could not
generate CGLIB subclass of class [class com.sun.proxy.$Proxy54]:
Common causes of this problem include using a final class or a
non-visible class; nested exception is
java.lang.IllegalArgumentException: Cannot subclass final class class
com.sun.proxy.$Proxy54
When I remove the proxyTargetClass = true, it works but the advices are not triggered.
Any help? Is there a way to start the spring integration flow without a gateway?
There is no class associated with the gateway Proxy so you can't advise it.
Is there a way to start the spring integration flow without a gateway?
Instead of using the gateway, declare a bean of type MessagingTemplate and use template.sendAndReceive(someMessage) or template.convertSendAndReceive(somePojo) instead. See here.
(The gateway uses a MessagingTemplate internally; the gateway unwraps a MessagingException and throws the cause, the template does not).
It also does not support an error channel.
To get closer to the gateway functionality, you can subclass MessagingGatewaySupport and invoke its sendAndReceive() method(s).

How can I access Spring bean from Message-driven bean in JBoss AS 7

I want to make a call to a Spring bean (a #Component) from my message-driven bean (MDB) but have problems getting a reference to it. I've tried with a class implementing org.springframework.context.ApplicationContextAware which stores the Spring ApplicationContext in a static field in a class MyAppContext. The static field in MyAppContext is then accessed from the MDB. But MyAppContext is loaded from different classloaders. The Spring application context is correctly set in the web module classloader context, but in the MDB's classloader context, it's null.
Can I somehow instruct JBoss to use the same classloader for the web app and the MDB?
Or is there a better way than storing the Spring application context in a static field?
Thanks for any advice!
A static holder for the context is not really a good idea. To make your beans available to other applications in a Java EE environment, you should consider making use of JNDI.
Unfortunately, there is no plain JNDI exporter available out of the box, but it's fairly easy to write one yourself, as shown in this blog post: http://maestro-lab.blogspot.ro/2009/01/how-to-export-spring-managed-bean-to.html
There is however a JndiRmiServiceExporter that you may want to look at.
Once your beans are bound to names in JNDI, they can be referenced using standard CDI in your message bean without worrying about class loading issues.
Why not use "ClassPathXmlApplicationContext" to load and look up for the Spring bean you require in your MBean?

Integration Akka with Spring and OSGI (No configuration setting found for key 'akka')

I'v added one Akka actor to my app that works with Spring and OSGI.
I try to use Actor from Spring #Component bean like this:
private final ActorSystem system = ActorSystem.create("actor-system");
private ActorRef managerActorRef = system.actorOf(Props.create(ManagerActor.class), "ldapManagerActor");
When I start the app it throws an exception (No configuration setting found for key 'akka'):
Instantiation of bean failed; nested exception is org.springframework.
beans.BeanInstantiationException: Could not instantiate bean class [com.myconpany....ByBean]: Constructor threw exception; nested exception is com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka'
I've look at this: doc. And seems the root of my problem is related to class loader that I should pass to/for akka-system and application.conf file that describes this.
But I could not find appropriate stets to make it all working so far.
Could someone help?
My tries:
Flowing this article.
When I put:
<bean id="actorSystem" class="akka.actor.ActorSystem" factory-method="create" scope="singleton"></bean>
I have the similar error:
Could not autowire field: private akka.actor.ActorSystem
com.typesafe.config.ConfigException$Missing: No configuration setting fou
nd for key 'akka'
If you just want to use Akka actors you don't need to pass in application.conf settings. You can just use the default. Make sure you have the config library on your class path.
You didn't mention what version of Akka youre using, however if you grab the latest Akka 2.2 RC you can use an IndirectActorProducer to handle the spring wiring.
See this article on how to do that; http://blog.nemccarthy.me/?p=272
You should also tell Spring to call shutdown on the ActorSystem to cleanly shutdown. There is also an updated guide on how to integrate the ActorSystem into Spring or a web app here

spring using CGLIB proxy even when class implements interface

I'm trying to use Spring AOP to intercept methods of my GWT-RPC application (using GWT-Server library, so RPC service doesn't extend RemoteServiceServlet). When I deploy my war to tomcat and start the application, CGLIB fails for some reason. But I don't understand why CGLIB is being used for proxying at the first place. Since my RPC class implements the interface, shouldn't it be using JDK dynamic proxies?
Is there anything I need to do to debug this issue? Kindly advise.
Note: FYI, Spring encounters this exception, but I believe that's a different problem, I'm unable to understand why CGLIB proxy is in the picture.
Caused by: net.sf.cglib.core.CodeGenerationException: net.sf.ehcache.CacheException-->Another unnamed CacheManager already exists
in the same VM. Please provide unique names for each CacheManager in the config
or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
Answering for the sake of other (rare) folks who might do the same mistake.
The aspect setup for spring AOP wasn't correct and was in fact trying to target almost all the classes in the context, which is why EhCache started causing problems as there were more than one CacheManager instances (because of CGLIB proxies as CacheManager doesn't implement an interface)

Resources