Java org.springframework.beans.factory.BeanCreationException:创建名为';实体管理工厂

Java org.springframework.beans.factory.BeanCreationException:创建名为';实体管理工厂,java,spring,Java,Spring,我运行了一个Spring boot项目并收到错误: Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2020-11-23 15:34:48.542 ERROR 10579 --- [ main] o.s.boot.SpringApplication : A

我运行了一个Spring boot项目并收到错误:

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2020-11-23 15:34:48.542 ERROR 10579 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/example/config/multitenant/HibernateConfig.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
显然,错误来自类,它无法自动关联JPA属性:

@Configuration
public class HibernateConfig {

    @Autowired
    private JpaProperties jpaProperties;

    @Autowired
    private DataSource dataSource;

    @Bean
    JpaVendorAdapter jpaVendorAdapter() {
        return new HibernateJpaVendorAdapter();
    }

    @Bean
    LocalContainerEntityManagerFactoryBean entityManagerFactory(
            DataSource dataSource,
            MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
            CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl
    ) {
        //Properties related to MultiTenancyStrategy Schema
        Map<String, Object> jpaPropertiesMap = new HashMap<>(jpaProperties.getProperties());
        jpaPropertiesMap.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
        jpaPropertiesMap.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
        jpaPropertiesMap.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);

        //Properties related to MultiTenancyStrategy Database
        //jpaPropertiesMap.put(Environment.MULTI_TENANT, MultiTenancyStrategy.DATABASE);
        //jpaPropertiesMap.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
        //jpaPropertiesMap.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);

        jpaPropertiesMap.put(Environment.FORMAT_SQL, true);
        jpaPropertiesMap.put(Environment.SHOW_SQL, true);

        LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
        em.setDataSource(dataSource);
        em.setPackagesToScan("com.example*");
        em.setJpaVendorAdapter(this.jpaVendorAdapter());
        em.setJpaPropertyMap(jpaPropertiesMap);
        return em;
    }

    @Bean
    @Scope(
            value = ConfigurableBeanFactory.SCOPE_PROTOTYPE,
            proxyMode = ScopedProxyMode.TARGET_CLASS)
    public JdbcTemplate jdbcTemplate() {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        SimpleNativeJdbcExtractor simpleNativeJdbcExtractor = new SimpleNativeJdbcExtractor() {
            @Override
            public Connection getNativeConnection(Connection con) throws SQLException {
                con.setSchema(TenantContext.getCurrentTenant());
                return super.getNativeConnection(con);
            }

            @Override
            public Connection getNativeConnectionFromStatement(Statement stmt) throws SQLException {
                return super.getNativeConnectionFromStatement(stmt);
            }
        };

        simpleNativeJdbcExtractor.setNativeConnectionNecessaryForNativeStatements(true);

        jdbcTemplate.setNativeJdbcExtractor(simpleNativeJdbcExtractor);

        return jdbcTemplate;
    }
}
@配置
公共类HibernateConfig{
@自动连线
私人物业;
@自动连线
私有数据源;
@豆子
JpaVendorAdapter JpaVendorAdapter(){
返回新的HibernateJavaEndorapter();
}
@豆子
LocalContainerEntityManagerFactoryBean entityManagerFactory(
数据源数据源,
MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl
) {
//与多策略模式相关的属性
Map jpaPropertiesMap=newhashmap(jpaProperties.getProperties());
jpapPropertiesMap.put(Environment.MULTI_-TENANT,MULTI-tenancystategy.SCHEMA);
jpaPropertiesMap.put(Environment.MULTI_-TENANT_-CONNECTION_-PROVIDER,MULTI-tenantconnectionproviderImpl);
jpaPropertiesMap.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER,currentTenantIdentifierResolverImpl);
//与多策略数据库相关的属性
//jpaPropertiesMap.put(Environment.MULTI_-TENANT,MULTI-tenancystategy.DATABASE);
//jpaPropertiesMap.put(Environment.MULTI_-TENANT_-CONNECTION_-PROVIDER,MULTI-tenantconnectionproviderImpl);
//jpaPropertiesMap.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER,currentTenantIdentifierResolverImpl);
jpaPropertiesMap.put(Environment.FORMAT_SQL,true);
jpaPropertiesMap.put(Environment.SHOW_SQL,true);
LocalContainerEntityManagerFactoryBean em=新的LocalContainerEntityManagerFactoryBean();
em.setDataSource(数据源);
em.setPackagesToScan(“com.example*”);
em.setJpaVendorAdapter(this.jpaVendorAdapter());
em.setJpaPropertyMap(jpaPropertiesMap);
返回em;
}
@豆子
@范围(
值=ConfigurableBeanFactory.SCOPE\u原型,
proxyMode=ScopedProxyMode.TARGET\u类)
公共JdbcTemplate JdbcTemplate(){
JdbcTemplate JdbcTemplate=新的JdbcTemplate(数据源);
SimpleNativeJJDBCExtractor SimpleNativeJJDBCExtractor=新SimpleNativeJJDBCExtractor(){
@凌驾
公共连接getNativeConnection(连接con)引发SQLException{
con.setSchema(TenantContext.getCurrentTenant());
返回super.getNativeConnection(con);
}
@凌驾
公共连接getNativeConnectionFromStatement(语句stmt)引发SQLException{
返回super.getNativeConnectionFromStatement(stmt);
}
};
simpleNativeJdbcExtractor.SetNativeConnectionNeccessaryForNativeStatements(true);
setNativeJdbcExtractor(simpleNativeJdbcExtractor);
返回jdbc模板;
}
}


我该如何解决这个问题?

您使用的是
Maven
还是
Gradle
?@TechGeek49它的Maven,可以共享pom文件是的,当然。我想看看上面的链接