0

I'm trying to inject messageSource bean to one my component classes.

Here is part of bean xml:

<context:annotation-config />

<context:component-scan base-package="com.mattis.test"/>

<bean id="localeResolver"
      class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    <property name="defaultLocale" value="en" />
</bean>

<bean id="messageSource"
      class="org.springframework.context.support.ResourceBundleMessageSource">
      <property name="basename" value="messages" />
</bean>

And in my component I've got this:

@Component
public class TestClass {

@Autowired
private MessageSource messageSource;

<-- more code goes here -->
}

Always when I instantiate TestClass, messageSource is null. I tried more bean xml and class configurations but none of them worked.

1
  • How do you instanticate the TestClass, by new? Commented Oct 21, 2013 at 6:42

1 Answer 1

5

You're manually calling new TestClass(). Spring autowiring only works on managed beans.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.