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 8179433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:59:53+00:00 2026-06-06T23:59:53+00:00

XML Configuration <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 />

  • 0

XML Configuration

<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"></bean>
</beans>

and MongoService looks like

@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() 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);
    }

I write my MongoServiceTest as

public class MongoServiceTest {

    @Autowired
    private MongoService mongoService;

    public MongoServiceTest() throws UnknownHostException {
        mongoRule = new MongoRule();
    }

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

        mongoService.putDocument(document);
    }

and I see failures in tests as

12:37:25.224 [main] INFO  c.s.business.persist.MongoService - host=null, port=0, database=null
java.lang.NullPointerException
    at com.business.persist.MongoServiceTest.testMongoService(MongoServiceTest.java:40)

Which means bean was not able to read the values from local.properties

local.properties

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

How do I fix this?

update
It doesn’t seem to read off the values even after creating setters/getters for the fields. I am really clueless now.

Update 01

After adding init() method and adding it to bean, it stil doesn’t work. I don’t even see Logging message
XML

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

MongoService

@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);
    }

How can I even debug this issue?

Thanks much!

  • 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-06T23:59:54+00:00Added an answer on June 6, 2026 at 11:59 pm

    There is one issue that I see here, you are instantiating a Mongo class inside MongoService constructor, however at this point your properties have NOT been injected in based on the local.properties file so the value of host, port and database will be null there.

    Instead, what you can do is to not instantiate Mongo class within Service constructor, let the properties get injected into MongoService the way you are doing it, then create it as part of a init-method which is called after your properties are set:

    in MongoService:

    public void init(){
        mongo = new Mongo(host, port);
    }
    

    and in your bean configuration:

    <bean id="mongoService" class="com.business.persist.MongoService" init-method="init"></bean>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML configuration as follows: <beans xmlns=http://www.springframework.org/schema/beans xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:aop=http://www.springframework.org/schema/aop xmlns:tx=http://www.springframework.org/schema/tx xmlns:context=http://www.springframework.org/schema/context xsi:schemaLocation=
<?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:aop=http://www.springframework.org/schema/aop xmlns:context=http://www.springframework.org/schema/context xsi:schemaLocation=http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.1.xsd>
<?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:p=http://www.springframework.org/schema/p xsi:schemaLocation=http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd> <bean id=viewResolver class=org.springframework.web.servlet.view.InternalResourceViewResolver p:prefix=/WEB-INF/jsp/ p:suffix=.jsp
I have been trying following: <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:jee=http://www.springframework.org/schema/jee xmlns:mvc=http://www.springframework.org/schema/mvc xmlns:p=http://www.springframework.org/schema/p xmlns:util=http://www.springframework.org/schema/util ................
So, I have springDM managed properties <beans:beans xmlns=http://www.springframework.org/schema/osgi-compendium xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:beans=http://www.springframework.org/schema/beans xmlns:osgix=http://www.springframework.org/schema/osgi-compendium xsi:schemaLocation= http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
I'm testing the Spring cache and, this is my context file <beans xmlns=http://www.springframework.org/schema/beans xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
I have an entry in my servlet.xml , xmlns:dwr=http://www.directwebremoting.org/schema/spring-dwr Now, what I think is,
I keep getting... org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: You cannot use a spring-security-2.0.xsd schema with Spring
How to determine what xmlns are required for beans component of my spring-servlet.xml(spring configuration
org.mule.api.lifecycle.InitialisationException: Initialisation Failure: Configuration problem: Unable to locate NamespaceHandler for namespace [http://www.mulesource.org/schema/mule/core/2.1] Offending resource:

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.