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

  • SEARCH
  • Home
  • 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 8155887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:47:43+00:00 2026-06-06T16:47:43+00:00

I have following situation – Have a MongoService class, which reads host, port, database

  • 0

I have following situation
– Have a MongoService class, which reads host, port, database from file

xml configuration

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>file:///storage/local.properties</value>
            </list>
        </property>
    </bean>
</beans>  

The local.properties looks like

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

and MongoService Class as

@Service
public class MongoService {

    private final Mongo mongo;
    private final String database;
    private static final Logger LOGGER = LoggerFactory.getLogger(MongoService.class);

    public MongoService(@Nonnull final @Value("#{ systemProperties['host']}") String host, @Nonnull final @Value("#{ systemProperties['port']}") int port, @Nonnull final @Value("#{ systemProperties['database']}") String db) throws UnknownHostException {
        LOGGER.info("host=" + host + ", port=" + port + ", database=" + db);
        mongo = new Mongo(host, port);
        database = db;
    }
}

When I want to test that bean is fine, I do the following in
MongoServiceTest.java

public class MongoServiceTest {

    @Autowired
    private MongoService mongoService;

}

It complains saying that can not identify bean for MongoService .

Then I add the following to above xml

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

Then it complains saying "No Matching Constructor found"

What I want to do

a.) MongoService should be @Autowired and reads configuration params from <value>file:///storage/local.properties</value>

Question

a.) Is accessing values in constructor are correct? (file name is local.properties and I am using @Value("#{ systemProperties['host']}") syntax)

b.) What is that I need to make it work so that @Autowired private MongoService mongoService loads correctly and reads value off local.properties file.

P.S. I am very new to Spring and don’t really know how to make this work

Thanks much for your help in advance

  • 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-06T16:47:45+00:00Added an answer on June 6, 2026 at 4:47 pm

    I think , You have to add constructor-arg to config xml as follows.

    <bean id="mongoService" class="com.business.persist.MongoService">
    
            <constructor-arg type="java.lang.String">
                <value>host</value>
            </constructor-arg>
    
            <constructor-arg type="int">
                <value>port</value>
            </constructor-arg>
    
            <constructor-arg type="java.lang.String">
                <value>database</value>
            </constructor-arg>
    
        </bean>
    

    I am not sure,Bst way could be adding java based bean config. Remove the bean definition from xml and add java-based congfig as follows

    @Service
    public class MongoService {
    
        private final Mongo mongo;
        private final String database;
        private static final Logger LOGGER = LoggerFactory.getLogger(MongoService.class);
    
    @bean
        public MongoService(@Nonnull final @Value("#{ systemProperties['host']}") String host, @Nonnull final @Value("#{ systemProperties['port']}") int port, @Nonnull final @Value("#{ systemProperties['database']}") String db) throws UnknownHostException {
            LOGGER.info("host=" + host + ", port=" + port + ", database=" + db);
            mongo = new Mongo(host, port);
            database = db;
        }
    }
    

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following situation: <input id=upload_trigger_btn type=file name=files[] multiple> <a type=submit class=button-normal-12px-ffffff href=#><span>Add
I have following situation. In a constructor of a pseudo class I attach a
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
I have the following situation. Im getting data from an external system in the
I have the following situation in code, which I suspect may be a bit
I have the following situation : abstract class X { abstract X someMethod (...)
I have the following situation: I have class User with the follwing properies :
I have the following situation: From within a view controller, I go about creating
I have the following situation: public abstract class A { private Object superMember; public
I have the following situation. I have a database of transactions about multiple contracts.

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.