java– 无法从Controller外部的MessageSource获取消息

java– 无法从Controller外部的MessageSource获取消息,第1张

概述当我尝试在@Controller类中获取消息时,一切正常,但是当我尝试时要在@Service或@Component类中实现相同,我收到以下错误:org.springframework.context.NoSuchMessageException: No message found under code 'email.ativacao.title' for

当我尝试在@Controller类中获取消息时,一切正常,但是当我尝试时
要在@Service或@Component类中实现相同,我收到以下错误:

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

我的控制器:

@Controllerpublic 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";     }}

我的服务:

@Servicepublic class TestService {    @autowired    private MessageSource message;    public voID getMessage() {        //Error        String message = message.            getMessage("email.ativacao.Title","BR"));    }}

我的组件:

@Componentpublic class TestComponent {    @autowired    private MessageSource message;    public voID getMessage() {        //Error        String message = message.            getMessage("email.ativacao.Title","BR"));    }}

我的配置:


            
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)