У меня есть фасоль mongoService, который выглядит вроде какSpring: NullPointerException происходит при включении боба
<?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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<context:property-placeholder location="file:///storage//local.properties"/>
<bean id="mongoService" class="com.business.persist.MongoService">
<constructor-arg value="${host}"/>
<constructor-arg value="${port}"/>
<constructor-arg value="${database}"/>
</bean>
</beans>
Мне нужно включить этот компонент в отдельном проекте, так что я создал банку для этого проекта, и добавил, в Maven зависимость, которая выглядит как
<dependency> <groupId>com.project</groupId> <artifactId>business</artifactId> <version>master-SNAPSHOT</version> </dependency>
Теперь в файле, где мне нужно, чтобы ввести это поле, я следующий
public class DocumentSaver implements IDocumentSaver { @Resource private MongoService mongoService; public boolean addDocument(Document doc) { // do other things // add document to mongo mongoService.putDocument(document); return true; } }
, а затем я запускаю тест следующим
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/com/wireup.xml")
public class DocumentSaverTest extends DocumentCase {
@Test
public void loadAndSave() {
DocumentSaver saver = new DocumentSaver();
Document doc = new Document();
// fill the doc
saver.addDocument(doc);
}
}
Я вижу NullPointerException
когда я бегу это на как saver.addDocument(doc);
Пожалуйста, скажите мне, что я я делаю неправильно
Спасибо