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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:51:49+00:00 2026-05-26T14:51:49+00:00

I have a service that needs to invoke a runnable class. Here are the

  • 0

I have a service that needs to invoke a runnable class.

Here are the lines of code that are being used in my service.

@Autowired
private LinkBrc2MemberProfile brcTask;                

// Background Task.
SimpleAsyncTaskExecutor sate = new SimpleAsyncTaskExecutor();
sate.createThread(new LinkBrc2MemberProfile(user));

Here is my Runnable class

@Service
public class LinkBrc2MemberProfile implements Runnable {

    private final Logger log = LoggerFactory.getLogger(LinkBrc2MemberProfile.class);

    @Autowired
    private LoyaltyDao dao;

    private Member member;

    public LinkBrc2MemberProfile() {
        super();
    }

    public LinkBrc2MemberProfile(Member member) {
        this.member = member;
    }

    public void run() {
        log.debug("*** Member User Name: " + member.getString("USER_NAME"));
        String emailAddress = member.getString("USER_NAME");
        Map<String, Object> map = dao.findBrcByEmailAddress( emailAddress );
        log.debug("==========================================================");

        if( ! map.isEmpty() ) {
            try {
                //a.CUSTOMER_ID, a.EMAIL_ADDRESS, b.card_no
                String customerId    = (String) map.get("CUSTOMER_ID");
                String brcCardNumber = (String) map.get("CARD_NO");

                log.debug("\ncustomerId: " + customerId + " brcCardNumber: " + brcCardNumber);
                if(!brcCardNumber.equals("")) {
                    // Add the Be Rewarded Card.
                    HashMap<String, String> userAttributes = new HashMap<String, String>();
                    String brcNumber = member.getString("BREWARDED_CARD_NO");
                    if (brcNumber.equals("")) {
                       userAttributes.put("BREWARDED_CARD_NO", brcCardNumber);
                       try {
                          member.putAll(userAttributes);
                       } catch (Exception e) {
                          String errorMessage = "Unable to save user's BRC information due to: " + e.getMessage();
                          log.error("{}", errorMessage);
                       }
                    }
                }
            } catch (Exception e) {
                log.error(e.getMessage());
                e.printStackTrace();
            }
        }
    }

I’m not seeing any errors in the log but at the same time it does not appear to be invoking the Runnable class. Am I missing an annotation somewhere? Are there any good examples that you can point me to, the only ones I have found use XML files to configure the runnable class I would like to use annotations. Thanks in Advance.

I’ve updated my service to do the following.

Please help, my DAO is NULL so it looks like my @Autowired in my Runnable class is not wiring it in.

I’ve added the following bean to my bean-config.xml file.

<bean id="brcType" class="com.ws.ocp.service.LinkBrc2MemberProfile" scope="prototype"/>

I removed my @Autowired annotation and added the following to my service class.

ClassPathResource rsrc = new ClassPathResource("bean-config.xml");
XmlBeanFactory factory = new XmlBeanFactory(rsrc);
LinkBrc2MemberProfile brcTask = (LinkBrc2MemberProfile) factory.getBean("brcType");                

SimpleAsyncTaskExecutor sate = new SimpleAsyncTaskExecutor();               
// Set Member attribute
brcTask.setMember(user);
// Executer
sate.execute(brcTask);

Why is my dao still null?

  • 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-26T14:51:50+00:00Added an answer on May 26, 2026 at 2:51 pm

    The runnable will throw a NullPointerException, since you create it yourself (using the new operator), instead of letting Spring create it. This obviously means that the autowired DAO attribute won’t be autowired, which will lead to a NPE when calling dao.findBrcByEmailAddress(...).

    You should get your Runnable instance from the bean factory (as a prototype), set its member attribute, and then submit it to the executor.

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

Sidebar

Related Questions

I have a service that needs to update the registry every 5 minutes (counteract
I have a web service that needs different settings for different environments (debug, test,
I have a WCF service that needs to notify it's clients when changes occur
I have a WCF service that needs to expose a custom collection to it's
I have a windows service that receives a large amount of data that needs
I hope you can help me. I have a web service that needs to
I have a JAX-RPC (Java) web service that needs to return a complex polymorphic
I have a web service on an insecure network that needs authorization. I wish
I have a WCF service, hosted in IIS 7.0 that needs to run database
I have a desktop application that needs to upload/download images to/from service computer over

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.