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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:04:53+00:00 2026-05-20T22:04:53+00:00

I have a problem with injecting a bean into a helper class. It works

  • 0

I have a problem with injecting a bean into a helper class. It works basically like this: I create an object in the page constructor that does some work, returns some data and I show these on the page. In this helper object, a service should be injected via @Autowired annotation. However, I always get a null pointer exception when I use it. I also tried @SpringBean but it didn’t help. On the other hand, when I inject this service directly into the page with @SpringBean, it’s accessible and works fine. Do you know where the problem is?

This is the page:

public class Page extends BasePage {
    public Page() {
        HelperObject object = new HelperObject(new Application("APP_NAME"));
        String result = object.getData();

        add(new Label("label", result));
    }
}

Helper object:

public class HelperObject {
    private Application app;

    @Autowired
    private Service service;

    public HelperObject(Application app) {
        this.app = app;
    }

    public String getData() {
        // use service, manipulate data, return a string
    }
}
  • 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-20T22:04:53+00:00Added an answer on May 20, 2026 at 10:04 pm

    @SpringBean only injects dependencies into classes that inherit from Wicket’s Component. @Autowired only injects dependencies into classes created by Spring itself. That means you can’t automatically inject a dependency into an object you create with new.

    (Edit: you can also add a @SpringBean injection to your class by injecting in the constructor:
    InjectorHolder.getInjector().inject(this);)

    My normal workaround for this is to use my application class to help. (I’m a little puzzled by your use of new Application(...). I assume this isn’t actually org.apache.wicket.Application.) For example:

    public class MyApplication extends AuthenticatedWebApplication implements
        ApplicationContextAware {
    
        private ApplicationContext ctx;
    
        public void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {
            this.ctx = applicationContext;
        }
    
        public static MyApplication get() {
            return (MyApplication) WebApplication.get();
        }
    
        public static Object getSpringBean(String bean) {
            return get().ctx.getBean(bean);
        }
    
        public static <T> T getSpringBean(Class<T> bean) {
            return get().ctx.getBean(bean);
        }
    
        ....
    }
    

    In my Spring application context:

    <!-- Set up wicket application -->
    <bean id="wicketApplication" class="uk.co.humboldt.Project.MyApplication"/>
    

    My helper object then looks up the service on demand:

    public class HelperObject {
    
        private Service getService() {
            return MyApplication.getSpringBean(Service.class);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problem with the injecting of my cookie into login.php page. This
i have a problem in inserting the listbox value into mysql database in vb
i have a problem in inserting the listbox value into mysql database in vb
I have a problem in php code inserting values into database (I use PHPMyAdmin).
I'm having a strange problem in that I have php inserting text into a
I have problem with my query on C, I’m using the oci8 driver. This
In C# I have an intrusive tree structure that looks like this: public abstract
I have an application config file that looks something like this: database: type: [db-type]
I have a class which needs a string as a parameter in its constructor
Hey, I have been searching all over for a solution to injecting into action

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.