Spring from a GWT - java

I have the next problem. I did simple project using Spring and Hibernate. Here is the structure of my project: (oh, I cant attach images).
Structure:
module "service" - the whole business logic;
module "war" - generates war file with client side part.
In a module war I have an .jsp page that generates table with data from database. There are also a few servlets. In my .jsp page I used Spring to get my service with movies.
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
MovieService bean = (MovieService) context.getBean("movieService");
List<Movie> movieList = bean.getAllMovies();
Now, I need to use GWT here. How can I use Spring in GWT app? I just add new module with GWT framework, and in entry class I can not use WebAppContext...
What should I use? However, I can directly use my service class, but it is not cool :) I want to use it like in .jsp page.
Thanks for any help!

If I understand correctly you have 3 options:
Use spring4gwt (maybe project is dead)
Use your controller as RESTful service (possibly it's not what you want)
Use spring like in this example
Also here you can find example of self-made analogue of spring4gwt, maye it works too

Related

Apache Karaf Rest Service Issue

I am having a WAB application which is just having only one html file, and its working fine. the code is available on the below git link
https://github.com/vineethvnair0/Karaf/tree/master/first-wab
Now I want to define a rest service in the wab, with the same context root as my web app for example like below.
http://localhost:8181/first-wab/rest/hello
Please let me know how can i do it?
Simply add a CXF servlet to the web.xml. The exact solution depends on how you expose your Rest endpoints. Do you plan to use spring?

How to use two URL mappings

I want to migrate my application to Spring Boot Jar Deployment. It currently uses Spring 4 without Boot.
I have a REST-API listening at /api/* and a Javascript-Frontend at src/main/webapp which can be accessed at /*.
Now i don't find a way doing the same in Boot.
I managed to get my api listening at /api/* by changing the server.context-path property but I didn't manage to register a second servlet to serve my js-frontend at /*. I know that src/main/webappis not supported by a jar deployment and i also know that Spring Boot serves static files from src/resources/public and src/resources/static. But in my case these folder then also points to /api/* because of the server.context-path change.
I tried is to register another servlet as a bean. This destroyed my api-endpoint.
What would be the best way to achieve this?
First option - copy everything from src/main/webapp into src/resources/static. This is where Spring Boot looks for that static content.
Second option, keep using src/main/webapp, but configure your build to copy the static resources into target/classes/static. I provided the Maven config for this on a previous answer: Refreshing static content with Spring MVC and Boot
Note that if you go with the first option, if you wish to modify content and have it automatically reloaded without running a build, you will need to run your application inside your IDE. Going with the second option gives you the usual Tomcat reloading of static content if you're executing your jar, but could lead to some confusion. Personally, I go with the second option most of the time, as I like to run the application on the command line and edit my HTML and JavaScript with Chrome Dev Tools.
For multiple mappings, you will have to add one per mapping and map that in controller like below.
#Controller
#RequestMapping(value = { "${url.mapping}","${url.mapping.two}" })
public class CustomerController{

jars required for REST service using spring

I am trying to implement a REST services using spring. I have added below JARS in the WEB-INF/lib and in Build path as well.
Spring core
Spring web
Spring MVC
Spring Context
Spring aop
Spring aspects
Common loggin
JSTL.
I have integrated the server in my Eclipse and started. When i try to hit the URL given in Spring controller, I am getting Resource not found Error. Exception I ma getting is ClassNotFound.
In the same project i have a HTML page when i try to hit it, its working fine.
Any jar i have to import or what may be the possible reason?
Have you explored SpringBoot? It is much easier to implement a REST based service. There are just 3 or 4 dependencies. You can find an example to implement a REST service here http://projects.spring.io/spring-boot/#quick-start
Search for the class using some utility like http://findjar.com and make sure that required dependency has been included in your project.
Do mvn dependency:tree to make sure that the respective project has been included.
If the respective project has been included, make sure that the class is there in the included version of the project.

how to access the bean from frontend to backend module in java

I have two module back end which contains all the spring implementation and dao implementation and i have other module frontend contains the jsp and html now i want to access the initialized bean of the backend from frontend.Please suggest the way if any one can help.
Thanks in advance.
You can access backend-beans if they are in same JVM. You can import the backend spring-configuration into the frontend-configuration (or by doing component scan if it's annotation driven). By doing this, those beans are simply available in front-end. (You can do this only if all the beans are in same JVM)

JSF 1.2 + Spring 2.5. How to?

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.

Categories

Resources