81,092
社区成员
发帖
与我相关
我的任务
分享
import java.util.List;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.ssh.dao.ShowSecretDao;
import com.ssh.entity.Secret;
public class ShowSecretDaoImpl extends HibernateDaoSupport implements
ShowSecretDao {
Session s = super.getSession(true);
public List<Secret> searchSecret() {
String hql = "from Secret";
@SuppressWarnings("unchecked")
List<Secret> secretList = super.getHibernateTemplate().find(hql);
return secretList;
}
public void addSecret(Secret secret) {
//getSessionFactory().openSession().save(secret);//这个方法可以成功
s.save(secret);//这个方法不成功
}
}
Could not instantiate bean class [com.ssh.dao.impl.ShowSecretDaoImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
Error creating bean with name 'showSecretDao' defined in file [D:\eclipse\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\mysecret_ssh\WEB-INF\classes\applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ssh.dao.impl.ShowSecretDaoImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
Error creating bean with name 'showSecretService' defined in file [D:\eclipse\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\mysecret_ssh\WEB-INF\classes\applicationContext.xml]: Cannot resolve reference to bean 'showSecretDao' while setting bean property 'showSecretDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'showSecretDao' defined in file [D:\eclipse\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\mysecret_ssh\WEB-INF\classes\applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ssh.dao.impl.ShowSecretDaoImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
Unable to instantiate Action, com.ssh.action.ShowSecretAction, defined for 'show' in namespace '/'Error creating bean with name 'showSecretService' defined in file [D:\eclipse\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\mysecret_ssh\WEB-INF\classes\applicationContext.xml]: Cannot resolve reference to bean 'showSecretDao' while setting bean property 'showSecretDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'showSecretDao' defined in file [D:\eclipse\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\mysecret_ssh\WEB-INF\classes\applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ssh.dao.impl.ShowSecretDaoImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocation">
<value>WEB-INF/hibernate.cfg.xml </value>
</property>
</bean>
<!-- action -->
<bean id="showSecretAction" scope="prototype"
class="com.ssh.action.ShowSecretAction">
<property name="showSecretService" ref="showSecretService"></property>
</bean>
<!-- service -->
<bean id="showSecretService" scope="prototype"
class="com.ssh.service.impl.ShowSecretServiceImpl">
<property name="showSecretDao" ref="showSecretDao"></property>
</bean>
<!-- dao -->
<bean id="showSecretDao" scope="prototype"
class="com.ssh.dao.impl.ShowSecretDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 显示实际操作数据库时的SQL -->
<property name="show_sql">true</property>
<!-- SQL方言,这边设定的是MySQL -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!--驱动程序,在后续的章节中将讲述mysql、sqlserver和Oracle数据库的配置 -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- JDBC URL -->
<property name="connection.url">jdbc:mysql://*********:3306/secret</property>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<!-- 数据库用户名 -->
<property name="connection.username">root</property>
<!-- 数据库密码 -->
<property name="connection.password">*******</property>
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">20</property>
<property name="c3p0.timeout">1800</property>
<property name="c3p0.max_statements">50</property>
<!-- 对象与数据库表格映像文件 -->
<mapping resource="com/ssh/entity/secret.hbm.xml" />
</session-factory>
</hibernate-configuration>