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?.
Related
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
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
I have a multi module Maven project. One of the modules is Spring backend that has DAOs, transactional services and REST controllers for some angular clients (Ionic framework)
Now I find the need to add a new Wicket module for a web client. This module uses the first module as a dependency. When I start the Wicket application the Spring context gets started from the dependency and the REST interface is available for the ionic clients. My issue is that I cannot tie the Wicket application to that existing Spring context. Wicket just wants to start a new Spring context with the same beans.
Now I can access the beans through some static methods from the spring context, but I want to use the #SpringBean annotation as in a regular Wicket+Spring application.
Is there a solution for this?
Thank you!
Wicket does not start any Spring context, as long as you don't instruct it to do so. Are you using the filter init-param "contextConfigLocation"?
When you just register a Spring injector inside your application, it should pick up the default Spring web context (it uses Spring's WebApplicationContextUtils#getRequiredWebApplicationContext()):
getComponentInstantiationListeners().add(new SpringComponentInjector(this));
If I understand correctly, your Spring backend is a web application, not just a java module. You cannot not (should not) have this web application as a dependency to an other web application (your new Wicket module).
You should probably move your shared business logic in a new java module. This new java module can be a dependency of your 2 web applications (Spring backend and Wicket).
An other solution would be to have 3 web applications. Spring facade, Wicket facade and Spring backend. Spring facade and Wicket facade, would just be some simple REST Controller which would redirect the request to the Spring backend to execute the business logic.
I have to create java project that used only for rest webservices. I have to choose between SpringMVC and Jersey. I consider springMVC because we use SpringMVC in all our other projects. I considered Jersey because its standard(JAX-RS) and its created specially for Rest.
Would it be overhead to use SpringMVC for rest only web project? Or should I use Jersey(or any other JAX-RS implementation)
If you also know how to configure / develop the backend in both worlds (CDI, Spring) it is really up to you.
But if you are more experienced with Spring(MVC) I would suggest that you use it or take a look at spring boot (samples especially spring-boot-hateoas).
I know that the general consensus is to use one or the other, but we have a specific task where we would like to use our spring services from within a stateless ejb timer.
Is there a standard way of getting a spring service from outside the normal flow of my web app? (Note I'm using the stripes framework and it has built in spring support and I'm using this built in support to access my spring services normally)
According to the Spring manual you can configure an EJB 3 injection interceptor that will take care of injecting #Autowired springbeans into your EJB Session Beans.