how to access the bean from frontend to backend module in java - 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)

Related

How to detect unused spring beans configured in XML?

I have a java project in which many .xml files are present.
All these xml files contain many beans.
The test for unused is:
A bean that is defined but never injected.
A bean that is injected but is never called in the code.
A bean that is defined but never loaded into the Spring context.
Questions
How do I identify which bean is used or not?
Is there a utility to do that?
There is no tools for detecting the unused springbeans in xml file. You can use the Spring Tools Suite for detecting. But it is taking too much time for checking.
I think that you can use spring actuator to check the opposite problem - which beans have been loaded in your context.
https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html
Actuator endpoints allow you to monitor and interact with your
application. Spring Boot includes a number of built-in endpoints and
you can also add your own. For example the health endpoint provides
basic application health information.
The way that endpoints are exposed will depend on the type of
technology that you choose. Most applications choose HTTP monitoring,
where the ID of the endpoint is mapped to a URL. For example, by
default, the health endpoint will be mapped to /health.
beans Displays a complete list of all the Spring beans in your application.
Looking for all the beans which are unused requires scanning XML files within application, then you can compare it with the list of beans produced by actuator.

Spring from a GWT

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

Inject a bean from another application context?

Is it possible to inject a bean from a web application that deploy in another server!
I declare a scenario to myself, I have two web application that use spring framework and deploy separately in different application servers (one is TOMCAT and another one is WEBLOGIC),the first application has ServiceA and the second one has ServiceB, now I want to inject ServiceB in ServieA?
I try to do this with RMI once an another one with JMS, now I am wondering that:
Is it possible with another thing?
Is there any active project about this scenario exist?
How can share application context in spring framework, is it possible?
Thanks.
Bean is just an object in JVM. You certainly cannot use an object from one JVM in another JVM straightforward.
But you can do 2 things:
Use proxies - some objects that will have the same interface but invoke somehow to the proper server as implementation.
Use service-oriented architecture (SOA). Each server should have some limited set of beans that are responsible for their functionality. And all beans can interact with each other.
Maybe OSGI is suitable for this.
Web services, JAX-RS is the simplest. But JAX-WS provides you with the tools to automatically generate the client code.

Web Console for Spring Application Context

Is there a way to expose my Spring applicationContext via a servlet or webapp so that I can manipulate and inspect the beans in the appcontext.
You may want to have a look at the Spring Inspector a plug-gable component that provides programmatic access to any Spring based application at run-time. You can use Javascript to change configurations or manage the application behavior at run-time.
Not aware of a special tool/plug-in. Maybe this would do:
How can I determine Objects in application context?
Spring Insight might do the trick.

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