我有这样的Application.java:
package server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
@SpringBootApplication(exclude=HibernateJpaAutoConfiguration.class)
public class Application {
@Bean
public HibernateJpaSessionFactoryBean sessionFactory(EntityManagerFactory emf) {
HibernateJpaSessionFactoryBean fact = new HibernateJpaSessionFactoryBean();
fact.setEntityManagerFactory(emf);
return fact;
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
我的问题是我想在开始使用@SpringBootApplication的@ComponentScan之前为sessionFactory创建bean但是我不知道怎么能这样做
答案 0 :(得分:3)
根据我的理解,您希望在任何bean初始化之前首先初始化HibernateJpaSessionFactoryBean
,实际使用HibernateJpaSessionFactoryBean.
尝试使用@DependsOn
您可以将HibernateJpaSessionFactoryBean移动到另一个配置类,例如。仔细阅读example