开发者

Spring framework best practices: deploying a non-bean compliant component

开发者 https://www.devze.com 2023-01-21 20:10 出处:网络
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

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-friendl开发者_StackOverflow中文版y 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?


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:

  • via a FactoryBean
  • via JavaConfig
0

精彩评论

暂无评论...
验证码 换一张
取 消