【发布时间】:2017-06-13 05:39:25
【问题描述】:
如何在 CamelBlueprintTestSupport 中加载 spring 上下文 xml 文件以及如何在 spring 上下文 xml 中获取数据源对象,问题是我在 com.hotel.common.persistence 处遇到了类似 java.lang.NullPointerException 的异常。 dao.DAOFactory.getDAO(DAOFactory.java:27) 我的假设是 DAOFactory 类没有得到映射器类。对吗?
我已经和你分享了我的示例代码
这是我的测试课
公共类 ContextRouteGetAvailabilityXmlTest 扩展 CamelBlueprintTestSupport {
@Override
protected String getBlueprintDescriptor() {
return "OSGI-INF/blueprint/context-beans.xml,OSGI-INF/blueprint/context-config.xml,OSGI-INF/blueprint/context-route-getAvailability.xml";
}
@Override
protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services){
BasicDataSource datasource = new BasicDataSource();
datasource.setDriverClassName("com.mysql.jdbc.Driver");
datasource.setUrl("jdbc:mysql://my ip:3306/test");
datasource.setUsername("test");
datasource.setPassword("test1");
datasource.setConnectionProperties("useUnicode=yes;characterEncoding=utf8;");
services.put("dataSourceMySQL", asService(datasource, null));
}
}
这是我的 spring context.xml 文件
<osgi:reference id="dataSourceMySQL" interface="javax.sql.DataSource"/>
<bean id="mybatisConfig" class="org.springframework.core.io.ClassPathResource">
<constructor-arg value="/META-INF/config/mybatis-config.xml" />
</bean>
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceMySQL" />
<property name="configLocation" ref="mybatisConfig" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactoryBean" />
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.sia.csl.hotel.common.persistence.mapper" />
<property name="sqlSessionTemplateBeanName" value="sqlSession" />
</bean>
<bean id="daoFactory"
class="com.common.persistence.dao.DAOFactory" />
【问题讨论】:
标签: spring apache-camel jbossfuse