0 0

hibernate4 spring jpa 配置多租户出现初始化错误,完整文件在附件30

注释掉多租户配置是正常的,使用了多租户配置,就出现初始化错误了

 

部分错误信息:(完整错误信息在提问最下方)

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/D:/work/lms/web/src/main/webapp/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException

 

 

加多租户配置文件部分内容(完整文件在附件里):

applicationContext.xml:

	<!-- 配置 JPA Entity Manager -->
	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
		<property name="dataSource" ref="dataSource"/>
		<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/> 
		<property name="packagesToScan" value="lms.modules.**.entity"/><!-- 如果多个,用“,”分隔 -->
		<property name="persistenceProvider">
            <bean class="org.hibernate.ejb.HibernatePersistence"/>
        </property>
        <property name="jpaDialect">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
        </property>
		<property name="jpaProperties">
			<props>
				<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
				<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
				<prop key="net.sf.ehcache.configurationResourceName">${hibernate.ehcache.configFile}</prop>
				<prop key="hibernate.cache.use_second_level_cache">true</prop>
				<prop key="hibernate.cache.use_query_cache">true</prop>
				<prop key="hibernate.search.default.directory_provider">filesystem</prop>
				<prop key="hibernate.search.default.indexBase">${hibernate.search.default.indexBase}</prop>
				<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
				<!-- 加了下面3行多租户配置信息就报错 -->
				<prop key="hibernate.multiTenancy">SCHEMA</prop>
				<prop key="hibernate.tenant_identifier_resolver">lms.common.datasource.TenantIdResolver</prop>
				<prop key="hibernate.multi_tenant_connection_provider">lms.common.datasource.SchemaBasedMultiTenantConnectionProvider</prop>
				 
				<!-- <prop key="hibernate.hbm2ddl.auto">update</prop> -->
			</props>
		</property>
	</bean>

 

 配置信息里使用到的类(完整文件在附件里):

SchemaBasedMultiTenantConnectionProvider.java:

public class SchemaBasedMultiTenantConnectionProvider
implements MultiTenantConnectionProvider {

  private final DriverManagerConnectionProviderImpl connectionProvider
       = new DriverManagerConnectionProviderImpl();
  @Override
  public Connection getConnection(String tenantIdentifier) throws SQLException {
      final Connection connection = connectionProvider.getConnection();
      connection.createStatement().execute("USE " + tenantIdentifier);

      return connection;
  }

  @Override
  public void releaseConnection(String tenantIdentifier, Connection connection)
throws SQLException {
      connection.createStatement().execute("USE dbs");        
      connectionProvider.closeConnection(connection);
  }
...

 

 配置信息里使用到的类(完整文件在附件里):

TenantIdResolver.java:

public class TenantIdResolver implements CurrentTenantIdentifierResolver {
    
	public String resolveCurrentTenantIdentifier() {
		
		String tenantId = Users.currentUser().getTenantId();
		//tenantId = "dbs";
		return tenantId;
		
    }

	@Override
	public boolean validateExistingCurrentSessions() {
		// TODO Auto-generated method stub
		return false;
	}
}

 

使用maven管理的,部分版本信息为:

		<!-- version setting -->
		<spring.version>3.2.2.RELEASE</spring.version>
		<spring-data-jpa.version>1.3.0.RELEASE</spring-data-jpa.version>
		<hibernate.version>4.3.6.Final</hibernate.version>
		<hibernate-validator.version>5.0.1.Final</hibernate-validator.version>
		<hibernate-search.version>4.2.0.Final</hibernate-search.version>
		<druid.version>0.2.19</druid.version>
		<shiro.version>1.2.2</shiro.version>

 

 

完整错误信息:

2014-10-20 09:03:28.835:WARN::Failed startup of context org.mortbay.jetty.webapp.WebAppContext@19058533{/lms-web,D:\work\lms\web\src\main\webapp}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/D:/work/lms/web/src/main/webapp/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:741)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:549)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:224)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at runjettyrun.Bootstrap.main(Bootstrap.java:97)
2014-10-20 09:03:28.837:WARN::Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/D:/work/lms/web/src/main/webapp/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException:
java.lang.NullPointerException
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:126)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
    at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:67)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:288)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1547)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:439)
    at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:277)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:139)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.<init>(PersistenceExceptionTranslationInterceptor.java:79)
    at org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor.<init>(PersistenceExceptionTranslationAdvisor.java:71)
    at org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor.java:85)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1508)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1476)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:741)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:549)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:224)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at runjettyrun.Bootstrap.main(Bootstrap.java:97)
2014-10-20 09:03:28.857:INFO::Started SelectChannelConnector@0.0.0.0:8080

目前还没有答案

相关推荐

    【SpringBoot】员工管理系统狂神篇

    Spring Boot支持使用YAML或Properties文件进行配置,方便管理各种应用设置。在员工管理系统中,这可能包括数据库连接信息、服务器端口、日志级别等。 6. **Web开发** 使用Spring Boot构建的Web应用,可以结合...

    基于springboot的房屋租赁管理系统 Javaee项目,springboot项目

    - **初始化项目**:通过Spring Initializr在线生成项目骨架,选择所需的依赖。 - **配置数据库连接**:在`application.properties`中配置数据库连接信息,如URL、用户名、密码等。 - **创建实体类**:如`House`、...

    基于SpringBoot+BootStrip3的公寓管理系统.zip

    SpringData JPA和Hibernate等组件被用来处理数据持久化,允许开发者以更高级别的抽象来操作数据库,减少对SQL的直接依赖。同时,Spring Security可能被集成用于权限管理和认证,确保系统安全。 Bootstrap3则是前端...

    java基于SpringBoot的物业管理系统

    Spring Data JPA是Spring对JPA(Java Persistence API)的扩展,它使得数据库操作变得更加简单,支持ORM(对象关系映射)框架如Hibernate,让开发者能用面向对象的方式来处理数据库事务。Spring Security则提供了...

    公寓管理系统_jsp.zip

    用户信息存储在数据库中,可能使用SpringData JPA进行持久化操作。 2. **房源管理**:管理员可以添加、编辑和删除公寓房源信息,包括房间类型、面积、设施、价格等。这些信息会展示在前端界面供租户浏览。 3. **...

    基于SpringBoot的物业管理系统.zip

    SpringBoot是Java的一个框架,它简化了Spring应用的初始设置和配置。标签表明开发者使用Java编程语言,这是一门广泛应用于企业级应用开发的强大后端语言。 【压缩包子文件的文件名称列表】:pms-master “pms-...

    java课程设计作业:基于SpringBoot+BootStrip3的公寓管理系统.zip

    首先,SpringBoot是Spring框架的一个简化版,它内置了Tomcat服务器,自动配置了许多Spring组件,减少了项目的初始化工作。通过使用SpringBoot,开发者可以快速构建可独立运行的Java应用。在这个公寓管理系统中,...

    springboot大学生租房系统 LW PPT.zip

    在数据库层面,可能选用MySQL作为存储介质,利用JPA(Java Persistence API)和Hibernate作为ORM工具,实现对象关系映射,简化数据库操作。租户信息、房源详情、合同状态等关键数据可以通过Entity类定义,并通过...

    SetorAlocacao:租赁物业的计划和注册

    SetorAlocacao可能使用Spring Boot简化项目的初始化和配置,Spring Data JPA处理数据库交互。 4. **JPA与Hibernate**:Java Persistence API(JPA)是Java标准,用于对象关系映射(ORM)。Hibernate是JPA的流行实现...

    jhipster:开始学习 jhipster

    5. **数据库选择**:jHipster支持多种关系型数据库(如MySQL、PostgreSQL)和NoSQL数据库(如MongoDB),并且可以配置Hibernate ORM和Spring Data JPA。 6. **安全性**:jHipster内置OAuth2认证,支持JWT(JSON Web...

Global site tag (gtag.js) - Google Analytics