"ALRubinger" wrote : Jaikiran, you give a good example of why the spec dictates
the fields must be injected into static members. But it's OK to criticize
something for being stupid.
|
| "bcn" wrote : In real-world application that would make it almost useless.
|
| Yep.
|
| Imagine if MC or Spring or any injection container limited you in this
regard. The difference is whether your object is managed or not; if you create
your own objects, they're not managed and you can't expect injection. If you
get it from a container or other lookup store, then that's another story.
|
Indeed, the thing is that the main class in a client application is really the
only place where a class is loaded and a method is called by the runtime, so
this also basically makes it the only candidate for an injection target.
Unless, you would accept to run your application in a modified JVM where the
new operator is somehow intercepted by the client container. Personally I
wouldn't mind that, but I guess a lot of people would object to that.
anonymous wrote :
| I've never liked Application Clients as they are. In addition to these
programmatic limitations with injection into the Main class (which completely
destroys good program design), you're limited to obtaining services from only
one host.
|
I'm not sure if it's really limiting. The idea seems to be to separate your
application code from details of where the AS is located. If you inject your
main class with a factory EJB that serves to give you other EJBs at any
location in your client code that you desire, than I don't really see the
problem with that.
Something like:
| public class MainClass {
|
| @EJB
| public EJBFactory factory;
|
| public static void main(String args[]) {
| MyApp theApp = new MyApp();
| theApp.run();
| }
| }
|
| ...
|
| public class SomeClass {
|
| public void SomeMethod() {
| EJBFooBean bean = MainClass.factory.getEJBFooBean();
| bean.invokeBar(); // results in RMI class to AS
| }
| }
|
There's always room for improvement of course, and being able to use @EJB
EJBFooBean in SomeClass would be superb, but for the time being the pattern
shown above seems to do the trick.
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4223452#4223452
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4223452
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user