Announcement Announcement Module
Collapse
No announcement yet.
Abstract Class and MessageSource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Abstract Class and MessageSource

    Hi,

    I wanted to have an abstract controller that my other controllers extended, just to set up service objects and logging and such. My service objects are autowired fine and logging works, I am having a problem with the MessageSource though.

    my message source is defined in my application context like this:

    Code:
        <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">   
            <property name="basenames">
           		<list>
             		<value>messages</value>
             	</list>
             </property>  
        </bean>
    My abstract controller does this:

    Code:
    	@Autowired
    	protected MessageSource messageSource;
    
            ...
    
    	public MessageSource getMessageSource() {
    		return messageSource;
    	}
    
    	public void setMessageSource(MessageSource messageSource) {
    		this.messageSource = messageSource;		
    	}
    and my extending controller does this:

    Code:
    messageSource.getMessage("login.title", null, "My Page Title", null);
    When trying to run it I get a NullPointer exception on the messageSource line in my extending controller.

    I do have a login.title in my messages.properties.

    Can anyone see my problem? Cheers.

  • #2
    Sorry, it was my unit tests failing and I wasn't correctly injecting my MessageSource into them. Please ignore this, it isn't a problem.

    Comment

    Working...
    X