floater
Java Jedi
总版主
发贴: 3233
积分: 421
|
于 2005-04-15 02:20
1. As long as you have a valid reason, you don't care: 这种行为在一些人的眼里看来是不够地道的做法.
2. Let's forget Spring for the time being, just talk EJB. When we build a SLSB(stateless session bean), what do we need to do? We need to write the class, and the xml file. Now if you want to use Spring as well, you need to load (ac)application context from somewhere. But you are in the ejb container, so you can't load a file. So we load it to JNDI. Once we have ac, we can set the dependencies. Then we can call it.
This is the normal case and we need to do this for every bean. So Spring comes up those classes to do the common part for you. If you don't want to use them, it's ok. Try not to use it, build 3 slsb's, find the common/repetitive work in developing them, then you should see why/what Spring does it(or maybe not, sometimes I couldn't figure out what they are doing either, quite complex, e.g., the classloader part, when you get several classloaders there, it's hard to keep track of them. In Struts, they can't make it work *all the time* either. But Spring folks can do it.)
This, and others, like jdbc support, web controllers, jms, are not about invasion or Ioc container at all, they are about the support for J2EE. You don't need to use them at all. If you do it without them, with just regular j2ee classes and IoC container, it works. But once you do it more than 3 times, you would find some repetitive work that you are doing over and over again. Natually, you want to isolate them so you just do it once. So does Spring team, so they did it for you, and more than that.
You have choices: use j2ee only. use j2ee, and Ioc only, without Spring's j2ee support. use j2ee, Ioc, and Spring's j2ee support.
I would go with the last, because: 1. avoid repetitive work, e.g., hook ioc container with j2ee 2. spring team has more exp than me, so their practices are better than mine most of the time. 3. I don't need to maintain these hooks. If I go with J2EE version 8, they do the dirty work to upgrade, not me.
Yes, of course, the support part is invasive, because it hooks j2ee for you. They have to land somewhere, i.e., you can't just get j2ee for free(Ioc wise).
So you make the judgement.
My 2 cents. I sense that your logic is twisted, try to understand the purpose first and follow that direction. But I may be wrong. Just my opinion for discussion, no intention to disrespect anyone.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." - Martin Fowler, Refactoring - Improving the Design of Existing Code
|