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.
Related
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 requirement to load dynamic modules on a Spring Boot Microservice. i.e Assume I have a MicroService called ProductService that will create different kind of products. And assume that I want to dynamically add products so there I use OSGI product modules.
So if I add ProductXYZ as a OSGI module and how can I call a method on that module via Spring boot REST API. i.e
/products/id/description?name=ProductXYZ
Here the issue is, in Spring Boot (even Spring web MVC) these rest calls are handle in the controller. And to get description of ProductXYZ I should create an object of ProductXYZ in the controller. But when coding the controller class it is impossible to call "new ProductXYZ()" as we don't have ProductXYZ when coding controller. We have ProductXYZ in later after we add osgi ProductXYZ module.
Thanks.
I want to create an enterprise project (with EAR packaging) with following modules:
1.) I want to have my Spring beans in the EJB module.
2.) The Vaadin application should be the web module.
Now I have everything in one web project. I have the spring bean configuration in the applicationContext.xml. In the web.xml the application context is configured to get loaded. How can I move the spring beans and the context configuration into the EJB module and deal only with the Vaadin UI in the web module, having the beans automatically injected into my custom components? Thanks for your help.
Consider the Spring Stuff Vaadin add-on for help with Spring and Vaadin.
Disclaimer: I'm the author
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.
I am using Spring to manage my DAO & Services. And JSF for UI. I want to use dependency injection in my JSF backing-bean. There is an article that explained how I can do that.
But I have two separate projects: one for Service and one for UI. The Spring configuration file is located in Service project.
How can I connect both project with Spring? I want to annotate my JSF pages for DI.
You can achieve this by using Spring Web Flow.
Spring have examples which show:
A JSF centric approach where your Spring and JSF beans are managed/configured the JSF way (faces-config) and a
Spring centric approach where your beans (including ManagedBeans) are managed in the Spring Context.
See Spring Flow Web Home
If you mean that you have one WAR with web services defined in it, and another separate WAR with the JSF stuff, I think it's really two separate projects each with their own Spring configuration.
The web service WAR will use either Spring web services or perhaps HTTP remoting to expose your service interfaces to clients via HTTP. This will have one set of application context configuration, either XML or annotations.
The JSF WAR will have the JSPs and controllers. The controllers will be injected with clients that will interact with the remote services to accomplish what you wish. That's all they need to know about the service WAR. There doesn't need to be any duplication of configuration at all.
It's actually a nice design, because it completely decouples the view from the rest of the problem.
Thank for everyone I did it. My mistake was with bean initialization. I tried to access my injected bean in constructor, but must must did in #PostConstruct method. And all that time i tried to find mistake in my config file. But it was in such simply place :)
I find some solution one:
Sample Application using JSF, Spring 2.5, and Java Persistence APIs with Glassfish v2
. But I have problem with it.
I can post this problem hear or must create new topic? Sorry for stupid question, i'm newbie her.