xml配置文件如下:
/context:component-scan
<!-- 数据库连接池 非单例属性 scope="prototype"-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="jdbcUrl" value="jdbc:sqlserver://127.0.0.1;DatabaseName=HRMIP" />
<property name="user" value="sa" />
<property name="password" value="123456" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
dao层类代码如下:
@Repository
public class RemindDaoImpl implements IRemindDao {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public List<Map<String, Object>> queryRemind() {
String sql = "";
System.out.println(jdbcTemplate);
return null;
}
}
入口程序如下:
public static void main( String[] args )
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
RemindDaoImpl dao = new RemindDaoImpl();
dao.queryRemind();
System.out.println( "Hello World!" );
}
输出的jdbcTemplate为null,请帮忙看一下怎么回事