Results 1 to 2 of 2

Thread: Abstract Class and MessageSource

  1. #1
    Join Date
    Jun 2008
    Posts
    21

    Default 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. #2
    Join Date
    Jun 2008
    Posts
    21

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •