tags:

views:

635

answers:

4

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.

A: 

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.

duffymo
My service layer I'm packing in jar. My WAR has this jar in his dependency, I pack this JAR in my WAR. I'm new in JSF and Spring and maybe I not accurately described what I want. I can inject spring beans into JSF beans using jsf faces-config.xml. But for me annotation looks much better then xml. And that why i need that my jsf backing-beans was managed by spring too. Or it's not very good idea to do such thing?
masterzim
Sounds fine. You can do it either way. I like the annotations, too. I think it makes the code cleaner. I don't understand why the service layer has to be in a JAR. Why not just build it along with the rest of the app and package the whole thing in the WAR?
duffymo
Because, as your said in previous post it is a good thing to take my logic separated from UI. It is possible to do what I want without merging projects? Or maybe there are some other ways to using Spring injection in JSF?
masterzim
You can use Spring injection with JSF, but Spring can only manage objects that exist within its application context, its JVM. You can't inject objects from another project, running on another machine. That's how I'm reading your requirement. Do I have it wrong?
duffymo
I want that all that sings work under Tomcat. I think if my Services are simply JAR than they working in the same JVM with JSF. I want somth like this http://cagataycivici.wordpress.com/2007/12/19/annotate-jsf-beans-with-spring-25/ but with two separated project. One manage DAO and Service, one JSF. And they both working in one scope under Toncat.
masterzim
If you have the .class files in WEB-INF/lib in the same WAR as JSF, it'll all work. A JAR isn't necessary. You can't separate the two and have them using the same Spring context.
duffymo
A: 

I find some solution one http://blogs.sun.com/carolmcdonald/entry/sample_application_using_jsf_spring. 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.

masterzim
+1  A: 

You can achieve this by using Spring Web Flow.

Spring have examples which show:

  1. A JSF centric approach where your Spring and JSF beans are managed/configured the JSF way (faces-config) and a
  2. Spring centric approach where your beans (including ManagedBeans) are managed in the Spring Context.

See Spring Flow Web Home

JamesC
A: 

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 :)

masterzim