日期:2014-05-20  浏览次数:20789 次

ssh框架整合时遇到的一个很令人纠结的问题,望各位大侠不吝赐教,不胜感谢
遇到的问题是,业务逻辑层的组件好像未能注入到action组件中去,因为运行时,在action组件中就业务逻辑层的组件为空,从而导致空指针异常,现在要解决的是如何将其注入。
 

我的配置文件如下:beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-2.5.xsd
  http://www.springframework.org/schema/tx 
  http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
  <context:component-scan base-package="com.ocean.dao"></context:component-scan>  
  <context:component-scan base-package="com.ocean.service"></context:component-scan>
  <context:component-scan base-package="com.ocean.action"></context:component-scan>
  <context:annotation-config></context:annotation-config>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  <property name="url" value="jdbc:mysql://localhost:3306/design"/>
  <property name="username" value="root"/>
  <property name="password" value="111111"/>
  </bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>com/ocean/model/Course.hbm.xml</value>
<value>com/ocean/model/Manager.hbm.xml</value>
<value>com/ocean/model/Student.hbm.xml</value>
<value>com/ocean/model/Teacher.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
  <props>
  <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
  <prop key="hibernate.show_sql">true</prop> 
  <prop key="hibernate.hbm2ddl.auto">update</prop>  
  </props>
  </property>
</bean>
<!--下边是将sessionFactory注入到dao层的组件中去-->
<bean id="managerdao" class="com.ocean.dao.impl.ManagerDaoHibernate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!--下边是将dao层的组件注入到业务逻辑层中去-->

<bean id="managerservice" class="com.ocean.service.impl.MangerServiceImpl">
<property name="managerdao" ref="managerdao"></property>
</bean>
  <!--下边是将业务逻辑层的组件注入action层中去-->
  <bean id="loginaction" class="com.ocean.action.LoginAction">
  <property name="mgr" ref="managerservice"></property>
  </bean>
</beans>

在对应的代码中也已经添加了对应接受注入的set方法。

不知道我的上面这个配置文件有没问题,麻烦各位大侠看看,谢谢

------解决方案--------------------