当我从命令行运行我的应用程序(java -jar forward.jar)时,每个方法都可以正常运行,不会抛出任何异常。但是,当运行与Windows服务相同的应用程序时,我得到NullPointerException。
19.06.2014 14:44:46.442 [DefaultListableBeanFactory] [AbstractBeanFactory.java] [DEBUG] [Thread-0]忽略bean创建 FactoryBean类型检查的异常: org.springframework.beans.factory.UnsatisfiedDependencyException: 创建在URL中定义名称为“phoneNumberRepository”的bean时出错 [JAR:文件:/ C:/forward.jar /com/forward/persistence/db/PhoneNumberRepository.class]: 通过bean属性表示的不满意的依赖性 'sqlSessionFactory'::创建名称为bean的错误 'sqlSessionFactory'在URL中定义 [jar:file:/ C:/forward.jar!/ mybatis-context.xml]:调用init 方法失败;嵌套异常是java.lang.NullPointerException; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 在URL中定义名称为“sqlSessionFactory”的bean [jar:file:/ C:/prem-forward.jar!/mybatis-context.xml]:调用 init方法失败;嵌套异常是java.lang.NullPointerException
然后
引起: org.springframework.beans.factory.NoSuchBeanDefinitionException:没有 合格的bean类型 找到[com.forward.persistence.db.PhoneNumberRepository] 依赖:预计至少有1个bean有资格成为autowire 这种依赖的候选人。依赖注释: {@ org.springframework.beans.factory.annotation.Autowired(所需=真)} 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:988) 〜[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:858) 〜[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770) 〜[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486) 〜[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] ... 28个常见帧 省略
Hier ist my my myatat-context.xml定义:
<import resource="classpath*:datasource-context.xml"/>
<mybatis:scan base-package="com.forward.persistence.db" />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="typeAliasesPackage" value="com.forward.model"/> <!-- Register the short names of beans as aliases -->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.forward.persistence.db" />
</bean>
更新:PhoneNumberRepository.xml的定义如下
<?xml version="1.0" encoding="UTF-8"?>
<resultMap type="com.forward.model.PhoneNumber" id="phoneMap">
<result column="number" property="number"/>
<result column="partition" property="partition"/>
</resultMap>
<select id="findAll" resultMap="phoneMap">
SELECT *
FROM PhoneNumber
ORDER BY number;
</select>
MyBatis将interphace PhoneNumberRepository映射到此.xml文件以创建bean。
答案 0 :(得分:0)
问题在于Java服务在部署机器和编译项目的本地机器上有所不同。