当前Spring5.3.0,Hibernate5.4.3.Final
1.声明
当前内容主要为使用Spring整合当前的Hibernate,使用注解方式实现操作
2.demo
由于是纯注解方式,所以没有applicationContext.xml配置文件
AppConfig.java
import org.apache.commons.dbcp.BasicDataSource;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = {
"com.hy.java.spring.database.hibernate.anno.service" })
@PropertySource(value = {
"classpath:/com/hy/java/spring/database/hibernate/anno/db.properties" })
public class AppConfig {
@Value("${jdbc.driverClassName}")
private String driverClassName;
@Value("${jdbc.url}")
private String url;
@Value("${jdbc.username}")
private String username;
@Value("${jdbc.password}")
private String password;
@Bean