I am pretty new to spring and currently I was able to create a complete web service with spring-ws. Now I want to separate the functionalities of my web service in to two separate web services. But except the service layer there are other spring components (business layer) which are common to both of these services.
So my question is there a way to make spring web service depend on another spring project (business layer)? If you can provide such example or a tutorial where a spring web service depends on another spring project it will be really helpful.
Thanks in advance.
UPDATE
I could achieve above by building my business layer as a jar file and adding it as a dependency to the service. But now my supervisor wants me to deploy the business layer in a separate server. But I could not find any information on how to handle communication here between web service and the business layer. Any idea?
Related
I'm building a new Java web app using Spring MVC framework and, at the same time, i'm building a mobile app using an hybrid framework (Cordova etc...). All modules are in the same project in Intellij and I'm using Maven as repository.
I would like share the business logic between the web app and the mobile app but i cannot move the spring service layer out of the Spring MVC.
I tried to create a new Java module in the project but I cannot understand how can I link the module between the 2 apps, using the right architecture.
Can I move the service layer out of the web app, in an external Java module?
If I cannot do this, how can i manage a shared business logic beetwen the web app and mobile app?
Ask me for any doubts.
Thanks!
That is a very common question people new to Java ask.
What my approach is; when I develop an application, I write the business action and controller classes in separate packages and reference them through JARs.
If you are using spring, you can add some custom functionality to controller classes by extending them (I am assuming you are not using annotations) so that they can execute your business action classes which are provided to them by using beans.
I would like to know is there any api/tool which automatically deploys ear/war/war-inside-ear and then injects mocks in the facade layer to make it suitable for testing.
I heard that rest assured api is one such api. But I did not come across tutorials or example which explains how to write code to deploy the ear/war/war-inside-ear in a default web server(netty/jetty) and test the web services.
Till now we are deploying our ear in jboss(without any mock data) and testing the web services using aur own custom apis.
P.S.
I have an ear which contains a war module. All my web service classes are in it. To test the request and response of the web services, I am deploying the actual web services and other ejbs in a jboss instance which requires lot of effort and setup. And then I am testing the requests and responses of all web services.
I am looking for a tool which deploys the ear and inject mocks in the web service classes instead of initializing all the ejbs inside the ear. This will reduce my effort for the setup I have to do to get the ejbs run.
I'm starting new application. I would like to have all business logic and domain classes separeted in standalone module (something like remote EJB). This is because of the app will have at least two (later more may be) clients - Desktop, Web (Spring MVC).
Is this possible with Spring? Or should I use EJB and Spring only for MVC in web app client?
Thank you for reply.
Yes, this can be done. You'll either put the resulting jar as a library in your full application, or host is separately and use some remoting system (hessian, soap, rmi, ...) to interface between them. Spring can help with that as well.
I'm wondering if it is possible to create XML-RPC server component within EJB module without servlets. I know EJB typically uses RMI as communication protocol but what if I want to omit RMI. What if i want to exchange data between EJB and web module (WAR) or other clients by different way like XML-RPC.
Can EJB-module work as stand-alone unit which will expose its state and services as XML-RPC server?
I still can do EJB module connected with WAR via RMI while this WAR will expose those services via servlet. Then other WARs or whatever-they-are clients can call this first WAR. Is this right or there is some other possibility?
What you probably want is to use Spring Remoting to expose your EJBs via for instance JAX-WS. Spring will create automatically servlets for handling the requests for you. The bad news is that you have to call your EJBs from the remoting services you build - meaning some boilerplate code. It should be quite straight forward though.
An other possibility you might take a look at is Restlet which can be used to build restful services.
In EJB3, your service beans are just annotated POJOs. You can simply annotate the same POJOs with #WebService (and the rest of this family of annotations) to expose the same services as web services.
I realize this isn't strictly what you asked for as the implementation for services exposed in this way is JAX-WS which uses SOAP messages. But I think it achieves your intent.
I am currently learning Spring. So far I have created a basic application consisting of Hibernate/JPA entities, DAOs and classes that perform business logic. This I am calling the service layer.
If I now wish to use SpringMVC to add a web front end to this application, how should I separate the two?
i.e. do I need to create a separate 'Dynamic Web' project in Eclipse for the web layer? If so, how do I then integrate the two? I presume I could simply copy the service layer source into the web project, but this doesn't seem like the best approach.
You don't need a separate project, it really depends on whether you'll be reusing your services elsewhere.
If you won't be reusing your services, add your web layer to the same project, have your controllers call your service layer, and build a WAR from it.
If you will be reusing your services, create a new project for you web layer, build a JAR for your services, and import that JAR into your web layer. Something like Maven will help here.
Are you using Maven? If so, you should create a webapp project and add your "core project" as a dependency.