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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:40:19+00:00 2026-05-27T15:40:19+00:00

I have a class that uses a method from a bean. I’m trying to

  • 0

I have a class that uses a method from a bean.

I’m trying to inject that method into my class using @Autowired, but it gives me NullPointerException.

public class ChangePasswordServiceImpl extends RemoteServiceServlet implements
        ChangePasswordService {

    @Autowired
    @Qualifier("userDetailsManager")
    private JdbcUserDetailsManager userDetailsManager;

    @Override
    public void changePassword(String oldPassword, String newPassword) {

        // This is the line that throws NullPointerException, i.e., userDetails
        // Manager is not being injected by Spring
        userDetailsManager.changePassword(oldPassword, newPassword);

    }

}

My xml file:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="
             http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
             http://www.springframework.org/schema/jdbc
             http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
             http://www.springframework.org/schema/context
             http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:annotation-config/>

    <bean id="securityDataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">

        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url"
            value="jdbc:mysql://localhost:3306/login" />
        <property name="username" value="root" />
        <property name="password" value="password" />
    </bean>

    <bean id="userDetailsManager"
        class="org.springframework.security.provisioning.JdbcUserDetailsManager">
        <property name="dataSource" ref="securityDataSource" />
        <property name="authenticationManager" ref="authenticationManager" />
        <qualifier value="userDetailsManager"/>
    </bean>

</beans>

Why is this field not being filled? Am I missing something?

  • 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-05-27T15:40:22+00:00Added an answer on May 27, 2026 at 3:40 pm

    Since ChangePasswordServiceImpl is not a Spring managed class (it is not in the xml configuration, therefore it is not a part of the ApplicationContext) @Autowired will do nothing for your class, which will cause you to get a NullPointerException when you try to use an instance of the class.

    You should define a bean for ChangePasswordServiceImpl in your xml configuration, along with the rest that are currently there.

    <bean id="changePasswordService" class="the.package.ChangePasswordServiceImpl"/>
    

    Finally, you can then get a hold of it via the ApplicationContext.

    //assuming you are holding onto an instance of the ApplicationContext
    ChangePasswordServiceImpl service = appContext.getBean("changePasswordService", ChangePasswordServiceImpl.class);
    service.changePassword("old", "new");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method I'm writing that uses reflection to list a class's static
I have a class that has a new method and uses that object to
I have a class that inherits from UIView However when trying to use the
I have a class that uses XStream and is used as a transfer format
I have a class 'Data' that uses a getter to access some array. If
I have a custom class that uses boost mutexes and locks like this (only
Is it good practice to have a class constructor that uses default parameters, or
I have created a button CSS class that uses background images with different positions
Let's say that I have class , that uses some functionality of dict .
I'm working on someone's code and they have a constructor that uses: class qwerty

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.