How do i pointcut the execution of functions defined in the Hibernate Entities, Which is not created or loaded as spring beans. Couldnt find any help over internet to how to do this.
Is there a way to use spring to point cut hibernate entities.
This is what I found, but no solution
With Spring AOP, you cannot do it. Spring AOP is a limited AOP solution that is only similar to AspectJ. Spring AOP is less capable than AspectJ in a number of ways:
Spring AOP supports only a limited subset of the AspectJ pointcuts (only execution type of pointcuts)
Spring AOP has different semantics compared AspectJ, because it uses dynamic proxies instead of direct bytecode manipulation. With the proxy based solution the Spring AOP uses, advices are not executed when the control flow doesn't leave the proxied object, as when invoking another method in the same object, like this.someOtherMethod()
Spring AOP only works for Spring managed beans. Hibernate entities are not Spring managed beans, so Spring AOP doesn't apply to them.
I encourage you to switch over to native AspectJ to be able to advise Hibernate entites or any other non spring managed beans. Spring supports AspectJ nicely and you should be able to change your configuration to use native AspectJ instead of Spring AOP.
Related
I had used Spring framework in my apps and while it is nice conceptually, it is not suitable for real-time apps due to its run-time overhead. For instance, http://apache-ignite-users.70518.x6.nabble.com/Failed-to-map-keys-for-cache-all-partition-nodes-left-the-grid-td23510.html shows the actual run-time Spring stack.
The Spring features that Ignite uses for loading application-defined beans are just many layers wrapped around simple Java reflection features. So Why Ignite uses Spring instead of straight Java'reflection ?
To make Ignite more performant, is there plan with Ignite to switch from Spring framework to Java reflection features ?
Similarly, if Ignite uses Spring Boot to handle port requests, why does it not use a light-weight framework such as www.sparkjava.com ?
Ignite uses Spring only to convert XML configuration files into configuration beans during startup. This way Ignite provides a convenient well-known way of configuring instead of introducing a custom one. In the runtime, after node is started, Spring is not used for anything.
In the thread you provided it's actually other way around - Spring invokes Ignite. Apparently, that's a Spring application with an embedded Ignite node.
I am having an issue with my Hystrix commands. If the call to hystrix wrapped method comes from within the class, the hystrix-wrapped method does not run in Hystrix enviroment
In that case I see logs as
05-02-2018 22:51:25.809 [http-nio-auto-1-exec-3] INFO c.i.q.v.e.ConnectorImpl.populateFIDSchema -
populating FID Schema
But, if I make call to the same method from outside the class, I see it running it in Hystrix enviroment
05-02-2018 22:54:53.735 [hystrix-ConnectorImpl-1] INFO c.i.q.v.e.ConnectorImpl.populateFIDSchema -
populating FID Schema
I am wrapping my method with HystrixCommand like this
#HystrixCommand(commandKey = "getSchemaCommand", fallbackMethod = "getSchemaCommandFallback")
Any ideas?
Contrary to #pvpkiran's answer, this is not a limitation of AspectJ, but a limitation Spring AOP. Spring AOP is a solution that tries to implement a subset of AspectJ through proxies, and the proxy based approach is what causing the advices not being called when the calls are not made through the proxy.
See Spring AOP capabilities and goals and AOP Proxies in the Spring Framework Reference for more details.
AspectJ on the other hand directly modifies the bytecode of the advised class, involves no proxies at all, and doesn't suffer from the limitation of the proxy based Spring AOP.
AspectJ is superior in pretty much all aspects to Spring AOP so I would advise you to switch over from Spring AOP to AspectJ (you don't need to ditch Spring for this as Spring and AspectJ can work together very well).
This is a limitation of Spring AOP (Hystrix-Javanica is based on AOP).
When you call a method locally, it doesn't go through a proxy and hence it doesn't really run in Hystrix environment, instead it runs as if it's another method.
But when you make a call from outside the class, it goes through proxy and hence it works.
This is true of many other functionalities. Another example is #Cacheable
When you call from outside the class, Hystrix (Spring AOP) intercepts the call and wraps it around its own environment. But when you do a call locally, it cannot intercept the call.
Is there a way to use Spring Cloud Sleuth with OpenTracing? I want to connect Spring clients with Jaeger
Spring Sleuth is now OpenTracing compatible. All you have to do is use OpenTracing Jars in your class path.
You can then use Sleuth-Zipkin to send instrumentation data to Jaeger's Zipkin collector.
This way you achieve everything you want with minimal configuration.
You can use my sample program as an example here:
https://github.com/anoophp777/spring-webflux-jaegar-log4j2
There's an ongoing discussion over here - https://github.com/spring-cloud/spring-cloud-sleuth/issues/599 . In general we don't explicitly use the OpenTracing API but we are Zipkin compatible in terms of header propagation. You can also manipulate the header names as you wish so if any sort of library you're using requires other header names for span / trace etc. then you can set it yourself as you want to.
We need to create a scalable application with a single instance of DB connection used across adapters , possibly want to use Spring hibernate for the same - how can we use mfp v 8 to implement such a use case.
would like to use the spring context to use common service beans across adapters
I do not believe you can use it across adapters, as each adapter lives in its own sandbox. You'll need to add it to each adapter separately as a maven dependency in its pom.xml file.
Is there any additional configuration that needs to be done in order to enable CDI JTA Transactions using #Transactional annotation under CDI beans with Weblogic 12.1.3 server?
I have tried to just add the annotation into a service method, but EntityManager didn't recognize to be running under a transaction.
Is there any interceptor or something else that needs to be registered?
#JoshAment is right.
WebLogic 12.1.3 only partially supports Java EE 7 (it supports its four pieces: JPA 2.1, JAX-RS 2.0, JSON-P 1.0, WebSockets 1.0). But #Transactional is a part of JTA 1.2.
Right now only Liberty Profile is fully certified against Java EE 7.
The planned year-end WebLogic 12.1.4 is going to support it also.
Anyway, answering your question: just configured persistence.xml should be enough to use the #javax.transaction.Transactional annotation in your code.
// You may also consider to move away from Java EE 7 ;) then you would be able to freely choose whatever lib you want. I strongly believe that server itself should not provide anything except servlets.