我已经在我的 servlet xml 中配置了 sessionfactory,并通过 SETTER 注入将其注入到 bean 中。我在bean的setter方法中放了一个日志。服务器启动后,我正在获取日志。似乎它正在将属性注入到我的 bean 中。但是当我调用该方法时,它会为空。附上我的代码..
<** Bean configuration Starts **>
<bean id="userServiceImpl" class="com.springapp.oranju.Service.UserServiceImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="sessionFactory"
class="
org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>/WEB-INF/config/hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<** Bean configuration ends **>
<** Bean Class starts**>
public class UserServiceImpl implements UserService{
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
try {
System.out.println(" **********************************************************************************"+this.sessionFactory.getReference());
} catch (NamingException e) {
e.printStackTrace();
}
}
public void validateLogin(UserVO userVO) {
System.out.println(sessionFactory);
sessionFactory.getCurrentSession().save(new User(new UserVO()));
}
}
<** Bean Class ends**>
<** call from controller starts **>
UserServiceImpl userService = new UserServiceImpl();
userService.validateLogin(new UserVO());
<** call from controller ends **>
I have tried using the @ Autowired.. but it was helpless.
Awaiting for a answer !.........