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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:05:09+00:00 2026-06-18T02:05:09+00:00

Everything works fine when I try to get messages in a @Controller class, but

  • 0

Everything works fine when I try to get messages in a @Controller class, but when I try
to achieve the same in a @Service or @Component class I receive the following error:

org.springframework.context.NoSuchMessageException: 
No message found under code 'email.ativacao.title' for locale 'pt_BR'.

My Controller:

@Controller
public class TestController {

    @Autowired
    TestService service;

    @Autowired
    TestComponent component;

    @Autowired
    private MessageSource message;

    @RequestMapping(value = "/send", method = RequestMethod.GET)
    public String go() {

            String message = message.getMessage
                   ("email.ativacao.title", null, new Locale("pt", "BR"));

            service.getMessage();

            component.getMessage();

            return "signsucess";
     }

}

My Service:

@Service
public class TestService {

    @Autowired
    private MessageSource message;

    public void getMessage() {
        //Error
        String message = message.
            getMessage("email.ativacao.title", null, new Locale("pt", "BR"));
    }

}

My Component:

@Component
public class TestComponent {

    @Autowired
    private MessageSource message;

    public void getMessage() {
        //Error
        String message = message.
            getMessage("email.ativacao.title", null, new Locale("pt", "BR"));
    }

}

My config:

<!-- i18n -->
<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.
                LocaleChangeInterceptor" p:paramName="lang"/>
</mvc:interceptors>

<!-- Mesage Source Config -->       
<bean id="messageSource"
    class="org.springframework.context.support.
        ReloadableResourceBundleMessageSource" p:fallbackToSystemLocale="true" >
    <property name="basename" value="WEB-INF/i18n/messages" />
</bean>

<!-- Mapeia o cookie que irá salvar as opções de idioma -->
<bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver"
    id="localeResolver" p:cookieName="locale"/>

MessageSource is not null on both @Service and @Component, but they’re not able to
get the message (Exception above). My properties:

WebContent/WEB-INF/i18n

  • messages_pt_BR
  • messages_en_US

I really can’t find the problem. Any suggestion to solve this? Thanks.

  • 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-06-18T02:05:11+00:00Added an answer on June 18, 2026 at 2:05 am

    From what you were describing, I guess controller bean and messageSource were declared in same context. so then can find each other.

    if your service bean and controller bean are not declared in same context, your service cannot find the messageSource.

    same context doesn’t mean same file. your one.xml could include two.xml.

    anyway, if it worked for you, it’s good.

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

Sidebar

Related Questions

I have my pickerview set up and everything works fine, but right now I
I am using hibernate annotations and when I do following everything works fine sessionFactory
As a general rule, everything works fine, but then sometimes either Eclipse or my
Everything works fine locally when I do as follows: cat input | python mapper.py
Everything works fine, the only problem is that it loads very slow. It takes
I have just added a product and everything works fine. The product is a
I developed an iPhone application using PhoneGap everything works fine, I sent the app
I have integrated to my project the mapkit framework and everything works fine. I
I am trying to do versioning with NHibernate and everything works fine, however right
I implemented this Jquery show/hide code and everything works fine except that the box

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.