2 回答

TA貢獻1851條經驗 獲得超4個贊
jdbcTemplate報空指針?
會不會setDataSource()沒執行,檢驗一下
再確定<context:component-scan base-package="sdf.dsf" />搜索到了TestDaoImp 這個類
或者換換寫法試試看吧
public void setDataSource(@Qualifier(value="dataSource") DataSource dataSource) {
this.dataSource=dataSource;
newJdbcTemplate();
}
public void newJdbcTemplate()
{
this.jdbcTemplate = new JdbcTemplate(this.dataSource);
}
配置方面貌似沒漏什么

TA貢獻1803條經驗 獲得超3個贊
你沒有配置sessionFactory
可以參考一下
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="namingStrategy">
<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
</props>
</property>
<property name="packagesToScan" value="com.idos.entity" />
</bean>
添加回答
舉報