For a few day I'm trying to solve a small problem. So, I have a Spring-Hibernate application. I've done one EJB to expose the services. With jUnit everything is OK. I'm loading the application context like this:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:/applicationContext.xml" }) @Transactional @TransactionConfiguration(defaultRollback = false) public class TestPatientServiceImpl { ....... }
The EJB is in one modul, the rest in another modul. (jar file) The problem is that I don't know how to load the applicationContext.xml from my EJB (with the spring beans and hibernate sessionFactory declaration).
Now when I'm trying to call my services from EJB, this (this is in my spring module, another modul than the ejb modul) does not work anymore
Well, usually Spring apps might call EJBs, but Very rarely the other way around, because people go to Spring so that they do not need to use EJBs.
SPring has <jee> namespace for looking up EJBs in your Spring application, but it can't do anything the other way around. You can expose your services as Corba. "RMI over IIOP", which is what EJBs use.
However, I would more question the design of using EJBs to front Spring, when you can expose Spring beans remotely in many other POJO based ways.
I have never seen an ApplicationContext object declared as a <bean> in xml, it is the ApplicationContext object that reads the xml file for bean declaration, not reading in itself to itself. So, why are you doing it that way? Just curious.
What object are you creating in code to read in that xml file?
Unless you are in the Web environment, code is usually
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml");
Mark
Gigi Kent
Ranch Hand
Joined: Nov 30, 2004
Posts: 40
posted
0
Juste curios. Do you know EJB? If yes, you should know that using setBeanFactoryLocator we are loading the xml file .
I apreciate to have answers from people who know not from people that never worked with it.
Originally posted by Corneliu Croitoru: Juste curios. Do you know EJB? If yes, you should know that using setBeanFactoryLocator we are loading the xml file .
I apreciate to have answers from people who know not from people that never worked with it.
Corneliu.
8 Years of EJB experience form 1.x to 2.x to EJB3, And I find your comment a little rude, our biggest rule here is be nice. I will leave you a bit of slack on this first offense. I am very nice about that.
So, you are accessing the Spring beans from EJBs, so your client is calling EJBs to get to your Spring Beans/services.
My comment is it seems that you are defeating the purpose of using Spring instead of EJBs. What benefits are you getting from the EJBs that you can't get from Spring alone in your environment?
Mark
Gigi Kent
Ranch Hand
Joined: Nov 30, 2004
Posts: 40
posted
0
So, the idea is that I have a service layer, and through EJB I want to expose some methods, in a Weblogic 9.2 to external clients. So, other applications can connect to it , and do some stuff. I'm using EJB because I have another app who can connect it self only to an EJB. So, EJB is not my choise.
So they (the apps) retrieve the EJB via a JNDI variable, and call one or more methods. Actually, I think my problem is not the transaction but maybe Weblogic 9.2 cannot handle with the spring annotations (like @Autowire).
I will try to replace the @Autowire with the old fashion spring injection to see if this works. If it will, this is bad news, because I will have to change my code.
PS: Sorry for my previous message
If this will do the trick, I'll post it.
Corneliu.
[ October 23, 2008: Message edited by: Corneliu Croitoru ] [ October 23, 2008: Message edited by: Corneliu Croitoru ]
Thanks, I actually should have asked that question up front. Sorry.
OK, so yes, you seem to have the configuration correct.
Something I noticed in some documentation. It stated,
In the above example, the ServicesConstants.PRIMARY_CONTEXT_ID constant would be defined as follows: public static final String ServicesConstants.PRIMARY_CONTEXT_ID = "businessBeanFactory";
Because I don't see a ServicesConstants class in the Spring Javadocs, it looks to be a constant that you declare, if you haven't already. (But also looking at your config, it looks like you already have it declared in your EJB)
I am curious to see how you experiment goes with @Autowire, but I am doubting that to be the cause. Because it is in a BeanFactoryPostProcessor class that handles the @Autowire annotation, in which Weblogic has no control over.
Another obvious question, is can you remote debug your code in your App Server. Do you have it configured so that you can set a break point in your IDE, and check out the code. One in the EJB, and one in the service class
Are you sure the Qualifier name is the name of the bean that you want injected? Trying to inject a Service into a DAO reference. Check higher up in your server logs to see if you don't have an expection earlier that the ApplicationContext failed to be created.
Originally posted by Corneliu Croitoru: The jUnit tests, are out of weblogic, in local. I'm testing only the service layer, in my eclipse environement. So.... I don't know.
I just replaced, the @Autowired with the old fashion injection way (via setter method) and now it's working.
So, the my conclusion is that there is a problem with weblogic 9.2 & @Autowire annotations.
Corneliu.
In the old fashion way, are you injecting the same "detailedPatientDaoService" or did you use a different bean name? I mean was the bean name supposed to be "detailedPatientDao" instead, and the @Qualifier just had a typo? So when you did it the old fashion way, you fixed that typo?
I am still thinking that Autowire should still work, I'll ask my co-workers via email.
Mark
Gigi Kent
Ranch Hand
Joined: Nov 30, 2004
Posts: 40
posted
0
The bean id is detailedPatientDaoService.
Here
the detailedPatientDao is only the name of my attribute. By any chance this could be the problem?
Now I have something like this
So, before using Qualifier I was specifying the bean id.
No not at all. Now that I see that indeed the bean id for that Dao does end with "Service".
Now, I have one more curiosity question. OK, the tests 100% pass, right? I also thought that @Autowire could only be on setters or constructors and not instance variables? I could easily be wrong there.
So my curiosity question. Can you try using the @Resource JSR-250 annotation instead of @Autowire, and see if maybe that might work. @Resource("detailedPatientDaoService")
Oh, and one of my co-workers asked which Java version Weblogic is using? No one else answered my email question about whether @Autowire in Weblogic 9 isn't working. Maybe I need to send it to the whole dev team. I will get an answer for you on that.