how handle Crosscutting concerns in jersy jaxrs - java

My problem is when we use Spring boot like framework, we can easily handle AOP. but how we handle AOP with jersy jaxrs project

Spring Boot is just a bootstrapping framework. For REST we can use Spring Boot to bootstrap Spring MVC or Jersey fully integrated with Spring. If you choose the latter route, then you can use the Spring AOP with Jersey. All you need to do is make your Jersey resources Spring #Components to able to intercept them. See an official example of Spring Boot and Jersey.
If you don't want to use Spring Boot to bootstrap your Jersey app, then you can still integrate Spring with Jersey. Remember the AOP is not tied to Spring Boot, it is tied to the Spring Framework, which are different things. You can see an example of Jersey with Spring (without Spring Boot) here.
If you don't want to involve Spring at all, then Jersey has a DI framework, HK2, which has it's own AOP. You can see a full example here

Related

Spring Data JPA without Spring MVC and Spring Boot

I want to make a small CRUD application using Spring Core and also I want to use Spring Data JPA.
How can I make such application without any web dependency or others like without using Spring MVC and Spring Boot.
Simple Spring Core + Spring Data JPA crud application.
Forget about whether it is recommended or not but is it possible?
Spring Boot is a architecture and it is not a framework. If you want to use Spring Core + Spring Data Jpa without spring-boot then go with maven quickstart.

whats the jersey analog for spring (boot) data's #Repository

ive been tasked with a total refactor of legacy code. It's a simple webservice, just an http request, then business logic with possibly a few database calls and a few other microservice calls, then a json response. I am being pushed not to use spring boot because no one else around me has used it before, and I was told jersey does everything spring boot does. I've never used jersey so im trying to find out how to do things that spring boot makes simple (ie repository layer with spring-data, caching, spring-consul, spring-zuul, spring-actuator, spring-circuit-breaker) It looks like jersey does do an analog of spring-security, bean validation, and easy insertion of servlet filters, but not everything spring-boot does. Is there an easy way to wire in a JPA type repository in jersey? I cant find it in the docs at https://jersey.java.net/documentation/latest/index.html.
I think about it this way. There are different layers in your application. You have a service layer, and you have a "REST layer". You access the Spring repositories with the service layer. Then you have the REST layer. With Spring, you have Spring MVC which is its web layer implementation, that you can also use as REST services. There is also Jersey, which is completely independent of Spring, which is a another REST layer options.
That be said, when using Spring MVC as the REST layer, adding the service layer with Spring data is seamless. But Jersey also has integration with Spring, that allows us to use Spring at the service layer inside our Jersey REST services. You check out this post which has some links to example of how this can be done (no hacking, this is supported out of the box). Using this approach, you can just injector your Spring data repositories into your Jersey resource class
interface PetsRepository extends JpaRepository<Pets, Long> {}
#Path("/pets")
class PetsResource {
#Autowired
private PetsRepository repo;
}
Now lets talk about Spring Boot. Spring Boot is just a bootstrapping framework. What it does is allow you to easily bootstrap an application without all the boilerplate configuration you would need without it. When your using Spring Boot for your REST services, you're not actually using Spring Boot itself as the REST service engine. You are only using it to bootstrap Spring MVC and maybe your Spring Data. But Spring MVC is the actual REST service engine.
Now like I said before, Jersey has support for integrating Spring into into it (for the service layer). Because of this support, Spring Boot has also provided a bootstrap configuration to integrate this support seamlessly. So instead of using the manual configuration that you would see in one of the examples linked to above, Spring Boot handles this configuration for us. So we can use Jersey as the REST layer, and Spring beans as the service layer. Check out the links below
See also:
Spring Boot docs for Jersey support

Does Spring Boot support servlet 2.5 auto-configuration?

I would like to create a Spring Boot application to be deployed on Google AppEngine infrastructure. GAE currently only supports servlet 2.5 web applications.
Is it possible to use Spring Boot - using auto-configuration - in combination with a old-fashioned web.xml?
Can I for example use a contextClass/contextConfigLocation pointing to a #Configration class including #EnableAutoConfiguration?
All Spring Boot examples seem to use a simple Application class with main method to run the application. So I would like to know if Spring Boot supports using a web.xml as start point to boot the application?
More than one question there:
There's nothing stopping you from using web.xml (it's still part of the Servlet spec). Most people prefer the Java initializers these days.
#EnableAutoConfiguration works for any application context (it just uses features of Spring).
But Spring Boot out of the box doesn't have a ContextLoaderListener that knows about SpringApplication, so you miss some of the benefits of Boot if you do as you describe. There's one you might find useful here.
Spring Boot Actuator relies on a few Servlet 3.0 features here and there so you need workarounds for a 2.5 environment (see this spring-boot-legacy prototype for details).
There's a sample app here that runs on GAE, currently deployed here: http://dsyerboot.appspot.com/.

Spring MVC and Ajax framework to use

I want to combine Spring MVC with AJAX capabilities in a Web application. I know that, for instance, DWR supports Spring by allowing you to expose Spring beans for remote invocation.
Is there a more suitable javascript framework to use when you are using Spring MVC as your Java Web framework?.

Is it possible to use Spring Security with Google Guice?

I would like to change Spring Framework to Google Guice, because it's lighter and has almost everything I need. Is it possible to use Spring Security with Google Guice instead of Spring Framework?
No. Spring Security makes extensive use of the core Spring Framework.
(I guess, in theory you could use Spring + Spring Security for the security filters, and Google Guice for the servlet wiring ... but I expect there would be a few traps and pitfalls on that road.)

Categories

Resources