Spring mvc messagesource在注释中失败

时间:2016-06-19 04:20:17

标签: spring annotations

我可以使用此代码检索邮件

public class UserApp {
    public static void main(String[] args) {

    ApplicationContext appContext 
        = new ClassPathXmlApplicationContext("application-configuration.xml");

    System.out.println(appContext.getMessage("NotEmpty.userForm.name", 
            new Object[] { 28,"http://www.mkyong.com" }, Locale.US ));

    }
}

但是使用ContextConfiguration Annotation使用相同的application-configuration.xml失败了。它正在向我展示

引起:org.springframework.context.NoSuchMessageException:在代码' NotEmpty.userForm.name'下找不到任何消息。对于语言环境' en_US'。

@Controller
@ContextConfiguration("/application-configuration.xml")
public class UserController {
    private static final Logger logger = 
        LoggerFactory.getLogger(UserController.class);

    @Autowired
    ApplicationContext appContext;

    @RequestMapping(value = "/users/add", method = RequestMethod.GET)
    public String showAddUserForm(Model model) {

        String temp = appContext.getMessage("NotEmpty.userForm.name", 
            new Object[] { 28,"http://www.mkyong.com" }, Locale.US ));
    }
}

应用-configuration.xml文件

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

我是否使用了错误的注释?

0 个答案:

没有答案