views:

34

answers:

1

I want to build an MVC app using Spring (first timer here).

As such I want to embed Jetty as the servlet engine. Jetty however doesn't stricly follow the java beans pattern, so I can't launch some classes from Spring (they use overloaded setters or non setter init methods like addXYZ).

What is the accepted/recommended practice for structuring this project? Obviously all my code fits nicely in the MVC model, but for Jetty:

  • Do I encapsulate all of Jetty (or any other non-bean friendly component) in my own Spring-friendly bean?
  • Do I try to instantiate as much of it as possible in spring and just extend classes that aren't bean con-formant to make them act like proper beans?
  • Is there another option?
+3  A: 

Generally speaking, I'm for the 2nd point - i.e. try to use spring utilities like factory-method, init-method, <constructor-arg> and things like that to overcome the fact that something is not entirely spring-friendly. It is rarely the case that it's impossible to configure beans with spring. And for the cases when it is impossible, create wrappers

You can also instantiate the 3rd party beans programatically:

Bozho
Oh don't get me started on their documentation, I've stared half witted with a blank face at that doc for hours. :) It's pretty old I think (invalid package references and it uses deprecated components), so I'm going the embedded route and following up-to -date code examples. Thanks for the suggestion, it helps to hear from other people out there, I don't have cube mates sitting near by.
David Parks
Another option that pops to mind is using Java Config... allows you to slip past the nasties (like the seemingly innocuous overloaded setter problem). I'd welcome any further comment on that idea too.
David Parks
@David Parks - yes, JavaConfig is also a good option. I'm now adding an update.
Bozho