[英]NullPointerException when initializing EbeanServer
I'm attempting to use EbeanORM to connect to MS SQL Server 2012. In addition, I'm using Spring and the jTDS driver. 我试图使用EbeanORM连接到MS SQL Server2012。此外,我正在使用Spring和jTDS驱动程序。
I'm getting the following exception when initializing the Spring context: 初始化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
Looking at the code in question , I see this is related to configuration. 查看有问题的代码 ,我看到这与配置有关。 It appears that an expected properties object is null, and it's not expected to be. 似乎预期的属性对象为null,而预期并非如此。
I do see the following error in the logs: 我在日志中确实看到以下错误:
16:39:12.070 [run-main-2] ERROR c.a.ebean.config.PropertyMapLoader - ebean.properties not found
This error is confusing to me. 这个错误令我感到困惑。 Since I'm using Spring to configure the EbeanServer
, it seems like I shouldn't need an ebean.properties
(EDIT: adding an empty ebean.properties
makes the error go away, but not the exception in question). 由于我使用Spring来配置EbeanServer
,似乎我不需要ebean.properties
(编辑:添加一个空的ebean.properties
可以使错误消失,但是没有问题的异常)。 In fact, at one point this setup was working (I could read/write to the DB). 实际上,在某种程度上,这种设置是可行的(我可以读写数据库)。 Now it's not, and I'm going crazy trying to figure out what changed. 现在不是,我发疯了,想找出发生了什么变化。
Here's my spring.xml
: 这是我的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>
Possibly relevant details: 可能相关的详细信息:
Figured it out myself, finally. 最后,我自己弄清楚了。
The Short Answer 简短答案
It appears that a new feature introduced in EbeanORM 6.4.1 breaks something. 看来EbeanORM 6.4.1中引入的一项新功能有些问题。 This is the feature in question: https://github.com/ebean-orm/avaje-ebeanorm/issues/390 . 这是有问题的功能: https : //github.com/ebean-orm/avaje-ebeanorm/issues/390 。
Downgrading (see below) to 6.3.1 resolves the issue. 降级(见下文)至6.3.1可解决此问题。
The Long Answer 长答案
I had been using EbeanORM 6.3.1 when I first got things working. 当我第一次工作时,我一直在使用EbeanORM 6.3.1。 I upgraded to 6.4.1, seeing that it had been released a couple days ago. 我升级到6.4.1,因为它是几天前发布的。 I noticed that things broke shortly after (no automated tests yet). 我注意到事情很快就破裂了(尚无自动化测试)。 I downgraded to 6.3.1 again, but this didn't fix things so I assumed it was a red herring. 我再次降级至6.3.1,但这并不能解决问题,因此我认为这是一个红鲱鱼。
Unbeknownst to me, SBT/Ivy was evicting 6.3.1 in favour of 6.4.1, even though I was explicitly depending on 6.3.1. 对我来说未知的是,即使我明确依赖于6.3.1,SBT / Ivy还是将6.3.1逐出6.4.1。 avaje-ebeanorm-spring
, which I'm also using, depends on avaje-ebeanorm
with version specifier [6,7)
. 我也在使用的avaje-ebeanorm-spring
取决于版本说明符[6,7)
avaje-ebeanorm
。 So, for some reason, SBT/Ivy decided that 6.4.1 was the best resolution of these two version requirements (WTF.... ). 因此,出于某种原因,SBT / Ivy决定6.4.1是这两个版本要求(WTF ....)的最佳分辨率。
I figured this out with this excellent plugin: https://github.com/jrudolph/sbt-dependency-graph . 我通过一个出色的插件解决了这个问题: https : //github.com/jrudolph/sbt-dependency-graph 。
To force SBT to give me 6.3.1, I modified my dependencies to add the exclude
: 为了强制SBT给我6.3.1,我修改了依赖项以添加exclude
:
"org.avaje.ebeanorm" % "avaje-ebeanorm" % "6.3.1",
"org.avaje.ebeanorm" % "avaje-ebeanorm-spring" % "4.5.3" exclude("org.avaje.ebeanorm", "avaje-ebeanorm")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.