Java 初始化EbeanServer时出现NullPointerException

Java 初始化EbeanServer时出现NullPointerException,java,spring,ebean,Java,Spring,Ebean,我正在尝试使用Ebenorm连接到MS SQL Server 2012。此外,我正在使用Spring和jTDS驱动程序 初始化Spring上下文时出现以下异常: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ebeanServer' defined in class path resource [spring.xml]: Invocation o

我正在尝试使用Ebenorm连接到MS SQL Server 2012。此外,我正在使用Spring和jTDS驱动程序

初始化Spring上下文时出现以下异常:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ebeanServer' defined in class path resource [spring.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
  at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
  at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
  at com.example.cloud.dal.Dal.<clinit>(Dal.java:48)
  ... 43 more
Caused by: java.lang.NullPointerException
  at com.avaje.ebeaninternal.server.changelog.DefaultChangeLogListener.configure(DefaultChangeLogListener.java:62)
  at com.avaje.ebeaninternal.server.core.DefaultServer.configureServerPlugins(DefaultServer.java:257)
  at com.avaje.ebeaninternal.server.core.DefaultServer.<init>(DefaultServer.java:248)
  at com.avaje.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:130)
  at com.avaje.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:45)
  at com.avaje.ebean.EbeanServerFactory.createInternal(EbeanServerFactory.java:108)
  at com.avaje.ebean.EbeanServerFactory.create(EbeanServerFactory.java:67)
  at com.avaje.ebean.springsupport.factory.EbeanServerFactoryBean.afterPropertiesSet(EbeanServerFactoryBean.java:54)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$6.run(AbstractAutowireCapableBeanFactory.java:1627)
  at java.security.AccessController.doPrivileged(Native Method)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1624)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
  ... 55 more
这个错误使我困惑。由于我使用Spring来配置
EbeanServer
,似乎我不需要
ebean.properties
(编辑:添加一个空的
ebean.properties
会消除错误,但不会出现问题中的异常)。事实上,这个设置在某一点上是有效的(我可以读/写数据库)。现在不是了,我要发疯了,想弄清楚是什么改变了

这是我的
spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
                      http://www.springframework.org/schema/beans/spring-beans.xsd
                      http://www.springframework.org/schema/context
                      http://www.springframework.org/schema/context/spring-context.xsd
                      http://www.springframework.org/schema/tx
                      http://www.springframework.org/schema/tx/spring-tx.xsd
                     ">

  <import resource="classpath:default-ebean-server.xml"/>

  <context:property-placeholder location="classpath:dal.properties" />

  <context:component-scan
    base-package="com.example.dal.service" />

  <context:component-scan
    base-package="com.example.dal.dao" />

  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="net.sourceforge.jtds.jdbc.Driver" />
    <property name="jdbcUrl" value="${db.jdbc_url}" />
    <property name="user" value="${db.user}" />
    <property name="password" value="${db.password}" />

    <!-- these are C3P0 properties -->
    <property name="initialPoolSize" value="${db.min_pool_size}" />
    <property name="minPoolSize" value="${db.min_pool_size}" />
    <property name="maxPoolSize" value="${db.max_pool_size}" />
    <property name="preferredTestQuery" value="SELECT 1" />
    <property name="idleConnectionTestPeriod" value="300" />
    <property name="connectionCustomizerClassName" value="com.example.dal.IsolationLevelConnectionCustomizer" />
  </bean>

  <tx:annotation-driven transaction-manager="transactionManager"/>

  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
  </bean>

  <bean id="serverConfig" parent="defaultEbeanServerConfig">
    <property name="name" value="serverConfig"/>
    <property name="packages">
      <list>
        <value>com.example.dal.model</value>
      </list>
    </property>
    <property name="dataSource" ref="dataSource"/>
  </bean>

  <bean id="ebeanServer" class="com.avaje.ebean.springsupport.factory.EbeanServerFactoryBean">
    <property name="serverConfig" ref="serverConfig"/>
  </bean>
</beans>

com.example.dal.model
可能的相关细节:

  • 爪哇8
  • 埃比诺姆6.4.1
  • 弹簧4.1.7.释放
  • avaje Ebenorm spring 4.5.3
  • jTDS 1.3.1

    • 最后我自己解决了

      简短的回答

      Ebenorm 6.4.1中引入的新功能似乎破坏了某些东西。这是有问题的功能:

      降级(见下文)至6.3.1可解决该问题

      长答案

      当我第一次开始工作时,我一直在使用Ebenorm 6.3.1。我升级到6.4.1,看到它已经在几天前发布了。我注意到事情不久就坏了(还没有自动测试)。我再次降级到6.3.1,但这并没有解决问题,所以我认为这是一个骗局

      在我不知情的情况下,SBT/Ivy将6.3.1逐出,取而代之的是6.4.1,尽管我明确地依赖于6.3.1
      avaje Ebenorm spring
      ,我也在使用它,它依赖于带有版本说明符的avaje Ebenorm,
      [6,7)
      。因此,出于某种原因,SBT/Ivy决定6.4.1是这两个版本要求(WTF…)的最佳解决方案

      我用这个优秀的插件解决了这个问题:

      为了迫使SBT给我6.3.1,我修改了我的依赖项,添加了
      排除

      "org.avaje.ebeanorm" % "avaje-ebeanorm" % "6.3.1",
      "org.avaje.ebeanorm" % "avaje-ebeanorm-spring" % "4.5.3" exclude("org.avaje.ebeanorm", "avaje-ebeanorm")
      

      在Ebean中有一个关于此的问题:。应在6.5.2中修复。
      "org.avaje.ebeanorm" % "avaje-ebeanorm" % "6.3.1",
      "org.avaje.ebeanorm" % "avaje-ebeanorm-spring" % "4.5.3" exclude("org.avaje.ebeanorm", "avaje-ebeanorm")