Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8185509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:52:20+00:00 2026-06-07T01:52:20+00:00

My wireup.xml looks like <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-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd> <util:properties id=mongoProperties

  • 0

My wireup.xml looks like

<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-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
    <util:properties id="mongoProperties" location="file:///storage//local.properties" />

    <bean id="mongoService" class="com.business.persist.MongoService" init-method="init"></bean>
</beans>  

and storage//local.properties as

### === MongoDB interaction === ###
host="127.0.0.1"
port=27017
database=contract  

The Bean class MongoService as

@Service
public class MongoService {

    @Value("#{mongoProperties['host']}")
    private String host;

    @Value("#{mongoProperties['port']}")
    private int port;

    @Value("#{mongoProperties['database']}")
    private String database;

    private Mongo mongo;

    private static final Logger LOGGER = LoggerFactory.getLogger(MongoService.class);

    public MongoService() {}

    public void init() throws UnknownHostException {
        LOGGER.info("host=" + host + ", port=" + port + ", database=" + database);
        mongo = new Mongo(host, port);
    }

    public void putDocument(@Nonnull final DBObject document) {
        LOGGER.info("inserting document - " + document.toString());
        mongo.getDB(database).getCollection(getCollectionName(document)).insert(document, WriteConcern.SAFE);
    }

    public void putDocuments(@Nonnull final List<DBObject> documents) {
        for (final DBObject document : documents) {
            putDocument(document);
        }
    }

I test this class in MongoServiceTest as

public class MongoServiceTest {
    @Autowired
    private MongoService mongoService;


    @Test
    public void testMongoService() {
        final DBObject document = DBContract.getUniqueQuery("001");
        document.put(DBContract.R_VARIABLES, "values");
        document.put(DBContract.P_VARIABLES, "values");

        mongoService.putDocument(document);
    }   

When I run this I enncountered NullpointerException

10:24:23.956 [main] INFO  c.s.sparrow.business.util.MongoRule -  Setting up Mongo Database
10:24:23.963 [main] INFO  c.s.sparrow.business.util.MongoRule - Shutting down the Mongo Database

java.lang.NullPointerException
    at com.business.persist.MongoServiceTest.testMongoService(MongoServiceTest.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
    at org.junit.rules.RunRules.evaluate(RunRules.java:18)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

It doesn’t seem like the wireup is actually creating a bean and calling the init method

Question

How can I fix this and make it work?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:52:22+00:00Added an answer on June 7, 2026 at 1:52 am

    use @ContextConfiguration

    @ContextConfiguration
    public class MongoServiceTest {
        @Resource
        private MongoService mongoService;
    

    Full test class should look like

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration
    public final class MongoServiceTest {
    
       @Resource
       private MongoServiceservice;
    
       @Test
       public void testServiceName() {//...
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following scenario: class A with bean-a in wireup.xml class B extends
I have a project called X which has wireup.xml laid as follows : X/
As I wire up my first fairly complicated Cocoa-Touch view I feel like I'm
Code bellow will create eventstore for named connection. var es = Wireup.Init() .UsingSqlPersistence(DB) .Build();
I wire up Shadowbox dialog provider to my links or button like this: <%=Html.ActionLink(Resources.Localize.Routes_WidgetsEdit,
If there are 3 interfaces like the following public interface IWeapon { void Kill();
Is there a way to perform compile time enforcement of event handling wireup? So
How do I wire up my web.xml to have a task happen every n
For the project I'm working on, I can't use the [dbo] schema. From looking
In my code behind I wire up my events like so: protected override void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.