nested exception is java.lang.IllegalArgumentException: Property 'sessionFac
org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'ht'...
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ht' defined in class path resource [pringconfig/SpringConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.hibernate3.HibernateTemplate pringconfig.SpringConfig.gethibernatetemplate()] threw exception; nested exception is java.lang.IllegalArgumentException: Property 'sessionFactory' is required
import javax.sql.DataSource;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean;
@Configuration
public class SpringConfig {
private @Value("#{jdbcProperties.url}") String jdbcurl;
private @Value("#{jdbcProperties.username}") String username;
private @Value("#{jdbcProperties.password}") String password;
@Bean(name="datasource")
public DataSource dataSource(){
return new DriverManagerDataSource(jdbcurl,username,password);
}
@Bean(name="sessionfactory")
public SessionFactory getsessionfactory(){
AnnotationSessionFactoryBean asFactoryBean=new
AnnotationSessionFactoryBean();
asFactoryBean.setDataSource(dataSource());
// asFactoryBean.setPackagesToScan("kq.bean");
return asFactoryBean.getObject();
}
@Bean(name="ht")
public HibernateTemplate gethibernatetemplate(){
HibernateTemplate htp=new HibernateTemplate(this.getsessionfactory());
//htp.setSessionFactory();
return htp;
}
} 展开
import javax.sql.DataSource;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean;
@Configuration
public class SpringConfig {
private @Value("#{jdbcProperties.url}") String jdbcurl;
private @Value("#{jdbcProperties.username}") String username;
private @Value("#{jdbcProperties.password}") String password;
@Bean(name="datasource")
public DataSource dataSource(){
return new DriverManagerDataSource(jdbcurl,username,password);
}
@Bean(name="sessionfactory")
public SessionFactory getsessionfactory(){
AnnotationSessionFactoryBean asFactoryBean=new
AnnotationSessionFactoryBean();
asFactoryBean.setDataSource(dataSource());
// asFactoryBean.setPackagesToScan("kq.bean");
return asFactoryBean.getObject();
}
@Bean(name="ht")
public HibernateTemplate gethibernatetemplate(){
HibernateTemplate htp=new HibernateTemplate(this.getsessionfactory());
//htp.setSessionFactory();
return htp;
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询