81,090
社区成员
发帖
与我相关
我的任务
分享
//注入业务层接口
private EmpEbi empEbi;
public void setEmpEbi(EmpEbi empEbi) {
this.empEbi = empEbi;
}
private DeptEbi deptEbi;
public void setDeptEbi(DeptEbi deptEbi) {
this.deptEbi = deptEbi;
}
public String input(){
// 从数据库读取部门列表,加载部门选项
List<DeptModel> deptList = deptEbi.getAll(); // 这行的deptEbi报空指针
ActionContext.getContext().put("deptList", deptList);
return "input";
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd ">
<!-- 配置Action -->
<bean id = "deptAction" class="cn.lim.erp.auth.dept.web.DeptAction" scope="prototype">
<!-- 注入sessionFactory -->
<property name="deptEbi" ref="deptEbi"></property>
</bean>
<!-- 配置Ebi -->
<bean id = "deptEbi" class="cn.lim.erp.auth.dept.business.ebo.DeptEbo">
<!-- 注入sessionFactory -->
<property name="deptDao" ref="deptDao"></property>
</bean>
<!-- 配置Dao -->
<bean id = "deptDao" class="cn.lim.erp.auth.dept.dao.impl.DeptImpl">
<!-- 注入sessionFactory -->
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd ">
<!-- 配置Action -->
<bean id = "empAction" class="cn.lim.erp.auth.emp.web.EmpAction" scope="prototype">
<!-- 注入sessionFactory -->
<property name="empEbi" ref="empEbi"></property>
</bean>
<!-- 配置Ebi -->
<bean id = "empEbi" class="cn.lim.erp.auth.emp.business.ebo.EmpEbo">
<!-- 注入sessionFactory -->
<property name="empDao" ref="empDao"></property>
</bean>
<!-- 配置Dao -->
<bean id = "empDao" class="cn.lim.erp.auth.emp.dao.impl.EmpImpl">
<!-- 注入sessionFactory -->
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd" >
<!-- SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
</props>
</property>
<property name="mappingLocations">
<value>classpath:cn/lim/erp/**/vo/*Model.hbm.xml</value>
</property>
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<!-- 给事务注入hibernate的连接池 -->
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 注解事务驱动 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- DataSource -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/erpdb"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Struts2加载 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring监听器 -->
<listener>
<!-- 监听器默认加载的是WEB-INF/applicationContext.xml -->
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 指定Spring框架的配置文件所在的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
</web-app>
<!-- 配置Action -->
<bean id = "empAction" class="cn.lim.erp.auth.emp.web.EmpAction" scope="prototype">
<!-- 注入sessionFactory -->
<property name="empEbi" ref="empEbi"></property>
<property name="deptEbi" ref="deptEbi"></property>
</bean>