@Bean(name="entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,@Qualifier("ds")DataSource datasource){
return builder.dataSource(datasource).packages("com.entity").persistenceUnit("per").build();
}
我正在尝试为LocalContainerEntityManagerFactoryBean创建bean,但是我收到的错误是,EntityManagerFactoryBuilder的春天启动bean中的EntityManagerFactoryBuilder没有bean将使用@EnableAutoConfiguration自动创建但是如何在非spring启动项目中创建。
完整代码:
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder ;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder ;
import org.springframework.boot.context.properties.ConfigurationProperties;
@Configuration
@EnableAutoConfiguration
public class configclass {
@Bean(name="cisEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean cisEntityManagerFactory(EntityManagerFactoryBuilder builder,@Qualifier("dscis")DataSource datasource){
return builder.dataSource(datasource).packages("com.cureissure.cis.entity").persistenceUnit("cis").build();
}
@Bean(name="dscis")
@ConfigurationProperties(prefix="spring.ds_cis")
public DataSource cisMysqlDataSource(){
return DataSourceBuilder.create().build();
}
}