I'm currently porting a large Rest Service app from WebSphere to a Springboot app running in Docker. In the original implementation, I had an AspectJ aspect wrapping around the invocations of all the methods in my JaxRS services. Using the runtime weaver, this worked just fine.
Now, I've moved all of those services and the aspect over to Spring boot, using Spring AOP to load the aspects. The problem I'm having is that the Spring AOP code only appears to apply the aspects to objects that are created/managed by Spring. Unfortunately, the JaxRS objects are being created by Jersey directly, and Spring never gets involved, so the resulting objects are not proxied by the AOP subsystem and as a result none of my aspects get called.
Does anyone know how I can get Spring AOP to manage the JaxRS services (or somehow tell Jersey to allow Spring to create the service instances)?
You cannot with Spring AOP. Spring AOP is a proxy-based "AOP lite" framework which only applies to Spring-managed beans, as explained in the Spring manual. If you need to apply aspects to other classes, it is pretty easy to switch from Spring AOP to native AspectJ via LTW (load-time weaving).
Related
We are thinking of how to migrate spring jersey app to webflux gradually, by converting jersey services to webflux controllers, and converting jersey filters to webfilters one by one, controlled by a feature flag. Since webflux can run on modern servlet containers, I am thinking of mapping the original path to a servlet that just does the forwarding based on the value of the feature flag. However, as I understand, spring boot does not allow webflux to co-exist with spring MVC/Jersey. What's a best way to migrate existing app to webflux?
I have just built a RESTful web service with Spring Boot.
I now want to utilise the RESTful web service and start making calls to it by building a java console application (eventually adding GUI and security).
I was wondering if I can use any of the Spring functionality outside of the Spring (Boot) environment and use it in my java console application? For example, can I use Spring's RestTemplate in my non-Spring java application to make the REST api calls? I am new to Spring and I want to stick as close to Spring as possible. I think you can't, but I just want to make sure.
If not possible, I know you can create non-web application with Spring. Is it possible to integrate a GUI? Might not be best practice, just exploring what is possible and conventional.
Spring Boot is not coupled, in any way, to an application type. You can run command-line only apps, batch apps, web apps or any other kind of apps with it. You can even benefit from Spring Boot's auto-configuration.
In the case of the RestTemplate you may want to import spring-web directly rather than spring-boot-starter-web. Or you could add the starter and exclude the embedded container (spring-boot-starter-tomcat). Spring Boot will auto-adapt and not start an embedded web server in that case.
I am using spring-boot to develop webservices, but I don't want to use WsConfigurerAdapter to define a WSDL and all, because I want to deploy my war into WAS7 and it does not support Servlet 3.0. So how would I add a web.xml configuration into my application.
Spring Boot doesn't support Servlet 2.5 out of the box, however you can use Spring Boot Legacy to get things working. Take a look at the Google App Engine sample application for an example of how to use Spring Boot Legacy and web.xml.
You may also be interested in this Spring Boot issue which is proposing to make Spring Boot Legacy an official part of Spring Boot.
In my project we are using JSF and Spring WS (web tier), EJB 3.0 (service layer) and JPA (integration layer). We have exposed EJB in Spring container.
All technologies are used with Spring. So, Spring is a used to bind all layers together. Hence, Spring is common for all layers of architecture.
I read that, many features provided by EJB is also available in Spring. Can't we replace EJB with Spring? Why, EJB and Spring both are used together.
I want to understand, what are benefits of using such architecture.
Spring is an alternative for EJB. Usually EJB and Spring are not used together unless it is a legacy application which is already developed based on EJB and Spring is wired later to support dependency injection and other framework benefits.
EJB is a heavy weight container which requires App containers like JBoss, WebSphere, or Weblogic.
Spring is a very light weight container which can be used in in web containers like Tomcat and even in Standalone applications. Also it provides support for many modules from front-end to back-end.
If there is a chance, you should consider replacing EJB with Spring bean in service layer.
Does it means that Spring provides all features which are available from EJB 3.0. Clustering and all other features of EJB can also be acheived from Spring.
looks to me you need tomcat or some other servlet engine for the web part.
what about data access part using hibernate and jms? Thanks.
No, you don't need an application server, you can see Spring as a proprietary, modular application server implementation / adapter. But you still need an a servlet container.
Data access part: you can use hibernate and some standalone connection pool
jms: Spring is not a JMS provider, but it nicely integrates POJOs with any JMS provider
Spring also has comprehensive transactions support
Finally you have jmx and aop support built-in and easy integration with bean validation, jpa, web services, rmi, jci, task scheduling, caching...
As you can see you can either use certified application server and Java EE stack or built on top of Tomcat and pick Spring modules you need. Sometimes Spring uses standard Java EE APIs (like JPA), more often it builts its own.