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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:02:54+00:00 2026-06-07T00:02:54+00:00

I have a bean mongoService which looks like as <?xml version=1.0 encoding=UTF-8?> <beans xmlns=http://www.springframework.org/schema/beans

  • 0

I have a bean mongoService which looks like as

<?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>   
  • I need to include this bean in a separate project so I created a jar for this project and added as maven dependency which looks like

        <dependency>
            <groupId>com.project</groupId>
            <artifactId>business</artifactId>
            <version>master-SNAPSHOT</version>
        </dependency>   
    
  • Now in the file where I need to inject this field, I do the following

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

and then I run the test as follows

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

I see the NullPointerException when I run this on the like saver.addDocument(doc);

Please tell me what is that I am doing incorrectly

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-07T00:02:55+00:00Added an answer on June 7, 2026 at 12:02 am

    You should not create “DocumentSaver” with NEW operator as follows, get that from Spring Application Context.

    DocumentSaver saver = new DocumentSaver();

    If you use NEW operation , Spring would not inject the dependent objects.

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

Sidebar

Related Questions

I have a Bean that looks like this Class Person{ private String name; private
I have something like that: faces-config.xml <managed-bean> <managed-bean-name>aBean</managed-bean-name> <managed-bean-class>some.pack.Bean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> I have a
I have bean like: <bean id=test> ........... <property name=myQuery value=select a,b,c from table1 where
I have a bean which I map to the database using Hibernate. I'm using
I have a bean of type string[] which has two or more values. I
I have a bean where I have a field CustAmount which is double, I
I have a bean definition in Spring and it's proxy counterpart which is meant
I have a spring bean that I get like this within a method- repAppCaller
I have a bean that has a couple of beans injected with the autowire
I have a bean which extends other Java file. When I create a Spring

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.