配置文件 :
<context:annotation-config />
<!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->
<context:component-scan base-package="com.et.service" />
<context:component-scan base-package="com.et.repository" />
<context:component-scan base-package="com.et.dao.impl"/>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:override.properties</value>
</list>
</property>
</bean>
<bean id="proxoolDataSource1" class="org.logicalcobwebs.proxool.ProxoolDataSource">
<property name="driver" value="${jdbc.connection.driverClassName}"/>
<property name="driverUrl" value="${dataSource.url1}"/>
<property name="user" value="${dataSource.username1}"/>
<property name="password" value="${dataSource.password1}"/>
<!-- 测试的SQL执行语句 -->
<property name="houseKeepingTestSql" value="${proxool.houseKeepingTestSql}"/>
<!-- 最少保持的空闲连接数 (默认2个) -->
<property name="prototypeCount" value="${proxool.prototypeCount}"/>
<!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁 默认30秒) -->
<property name="houseKeepingSleepTime" value="${proxool.hourseKeepingSleepTime}"/>
<!-- 最大活动时间(超过此时间线程将被kill,默认为5分钟) -->
<property name="maximumActiveTime" value="${proxool.maximumActiveTime}"/>
<!-- 连接最长时间(默认为4个小时) -->
<property name="maximumConnectionLifetime" value="${proxool.maximumConnectionLifetime}"/>
<!-- 最小连接数 (默认2个) -->
<property name="minimumConnectionCount" value="${proxool.minimumConnectionCount}"/>
<!-- 最大连接数 (默认5个) -->
<property name="maximumConnectionCount" value="${proxool.maximumConnectionCount}"/>
<!-- -->
<property name="statistics" value="${proxool.statistics}"/>
<!-- 别名 -->
<property name="alias" value="${proxool.m.alias1}"/>
<!-- -->
<property name="simultaneousBuildThrottle" value="${proxool.simultaneous-build-throttle}"/>
</bean>
<!-- 配置SimpleJdbcTemplate 0级数据源-->
<bean id="jdbcTemplateMiddle" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="proxoolDataSource1"></constructor-arg>
</bean>
<task:annotation-driven /> <!-- 定时器开关-->
<bean id="taskSchedule" class="com.et.service.WebJobService"></bean>
<task:scheduled-tasks>
<task:scheduled ref="taskSchedule" method="makeMultipleTask" cron="${cron.onStarWeek}" />
</task:scheduled-tasks>
</beans>
impl:
package com.et.dao.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import com.et.dao.PagingDao;
@Service
public class PagingDaoImpl implements PagingDao {
@Autowired
private JdbcTemplate jdbcTemplateMiddle; 、、、、、这里为null
@Override
public int getPageSum() {
// TODO Auto-generated method stub
String sql="select count(*) from TASK_DEPEND_LIST ";
return jdbcTemplateMiddle.queryForInt(sql);
}
@Override
public int getPageSumset() {
String sql="select count(*) from TASK_DEPEND_SET ";
return jdbcTemplateMiddle.queryForInt(sql);
}
@Override
public int getPageSumlist() {
// TODO Auto-generated method stub
String sql="select count(*) from TASK_LIST ";
return jdbcTemplateMiddle.queryForInt(sql);
}
@Override
public int getPageSumlog() {
// TODO Auto-generated method stub
String sql="select count(*) from TASK_LOG_LIST ";
return jdbcTemplateMiddle.queryForInt(sql);
}
@Override
public int getPageSumdefinition() {
// TODO Auto-generated method stub
String sql="select count(*) from TASK_TYPE_DEFINITION ";
return jdbcTemplateMiddle.queryForInt(sql);
}
}
test main:
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
JdbcTemplate jt = (JdbcTemplate) context.getBean("jdbcTemplateMiddle");
int count = jt.queryForInt("select count(*) from TASK_DEPEND_LIST");
System.out.println(count);
}
这样是成功的。
servlet 代码 :
@Autowired
TaskDependListDao dependListDao;
@Autowired
PagingDao pagingDao;
/*
* 标识 : 0、查询 1、删除 2、修改 3、新增 4、根据ID查对象
*/
private static String Identification;
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
Identification = request.getParameter("Identification");
if (Identification == null) {
Identification = "0";
}
if (Identification.equals("0")) {
int pageSize = 10;// 每页显示
int pageCount = pagingDao.getPageSum();// 总条数 、、、在这里报错了,空指针。
// 总页数
int pageSum = pageCount % pageSize == 0 ? pageCount / pageSize
: pageCount / pageSize + 1;
int pageIndex = 0;// 当前页码
String ixs = request.getParameter("pageIndex");