I'm new to the spring framework. I've weblogic 12. I created an ejb jar packaged into an EAR. So I've two entities: Person and Address and an EJB PersonEjb.
public class Address implements Serializable {
String city;
String state;
// getters/setters...
}
public class Person implements Serializable {
String name;
Address address;
// getters/setters...
}
@Stateless(name = "PersonEjbBean", mappedName = "PersonEjbBean")
public class PersonEjbBean implements PersonEjb, PersonEjbLocal {
@Autowired
Person person;
public void sayHi() {
return "Hello " + person.getName() + " from " + person.getAddress().getCity() + ", " + person.getAddress().getState();
}
}
I've the spring config xml files as follows
beanRefContext.xml
<bean id="businessBeanFactory" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg value="businessApplicationContext.xml" />
</bean>
businessApplicationContext.xml
<bean id="address" class="org.example.entities.Address">
<constructor-arg value="Tom" />
<constructor-arg value="IL" />
</bean>
<bean id="person" class="org.example.entities.Person">
<constructor-arg value="Tom" />
<constructor-arg ref="address" />
</bean>
This is the structure I have:
- EAR/
- EAR/APP-INF/lib/spring.jar
- EAR/META-INF/application.xml
- EAR/META-INF/manifest.mf
- EAR/ejb.jar
- ebj.jar has Person, Address, PersonEjb, beanRefContext.xml and businessApplicationContext.xml
I deployed the EAR successfully and jndi entries were set. I've a client running locally that does the following.
Properties p = new Properties();
p.put(Context.PROVIDER_URL, "t3://localhost:7001");
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
Context ctx = new InitialContext(p);
PersonEjb bean = (PersonEjb) ctx.lookup("PersonEjbBean#org.example.ejbs.PersonEjb");
System.out.println(bean.sayHi());
the bean is instantiated but the autowiring on person field in the EJB doesn't seem to happen...How do I make this work?
you get PersonEjb from JNDI, so your should be init Person field in EJB end.
this is not spring's business. if you want spring to do that, use Spring ejb component to deploy to JNDI and use client to call this.