Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 属性资源占位符配置器在spring mvc中不工作_Java_Spring Mvc - Fatal编程技术网

Java 属性资源占位符配置器在spring mvc中不工作

Java 属性资源占位符配置器在spring mvc中不工作,java,spring-mvc,Java,Spring Mvc,我无法读取application.properties文件,但可以读取.properties文件中的消息 我正在使用maven项目,我的两个属性文件都在资源文件夹中 下面是我的配置 public class WebAppConfig extends WebMvcConfigurerAdapter { // resource bundle configuration @Bean public ReloadableResourceBundleMessageSource messageSource(

我无法读取application.properties文件,但可以读取.properties文件中的消息

我正在使用maven项目,我的两个属性文件都在资源文件夹中

下面是我的配置

public class WebAppConfig extends WebMvcConfigurerAdapter {

// resource bundle configuration
@Bean
public ReloadableResourceBundleMessageSource messageSource(){
    ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
    String[] resources= {"classpath:messages"};
    messageSource.setBasenames(resources);
    return messageSource;
}

@Bean
public LocaleResolver localeResolver() {
    final CookieLocaleResolver ret = new CookieLocaleResolver();
    ret.setDefaultLocale(new Locale("en_IN"));
    return ret;
}

@Bean 
public LocaleChangeInterceptor localeChangeInterceptor(){
    LocaleChangeInterceptor localeChangeInterceptor=new LocaleChangeInterceptor();
    localeChangeInterceptor.setParamName("language");
    return localeChangeInterceptor;
}

// properties file configuration
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
    PropertySourcesPlaceholderConfigurer propertySources = new PropertySourcesPlaceholderConfigurer();
    org.springframework.core.io.Resource[] resources = new ClassPathResource[ ] { new ClassPathResource( "application.properties" ) };
    propertySources.setLocations((org.springframework.core.io.Resource[]) resources);
    return propertySources;
}
}
JSP:读取属性

spring:messagecode=“label.maxlength”

例外情况:

No message found under code 'label.maxlength' for locale 'en_in'
label.maxlength位于application.properties中,但如果我尝试从messages\u en\u in.properties中读取某些内容,则工作正常。为什么不从application.properties读取


谢谢

您可以尝试如下编辑代码://properties file configuration@Bean public static propertySourcesplaceConfigurer propertySourcesplaceplaceConfigurer(){propertySourcesplaceplaceConfigurer propertySources=new propertySourcesplaceplaceConfigurer();org.springframework.core.io.Resource[]resources=new ClassPathResource[]{new ClassPathResource(“application.properties”,“messages_en_IN.properties”)};propertySources.setLocations((org.springframework.core.io.Resource[]);return propertySources;}@Arpit您在我的代码中添加了messages_en_IN.properties,但在读取捆绑资源属性文件时没有问题。那么是否需要在.properties文件中添加message_en_?不,我的理解不同。你的代码写得很好。理想情况下,它应该可以工作,而且您还可以从@Arpit获得jsp上的属性值。我是否需要使用
。请看。将实现此功能并恢复。这是一种经典的方法。请说吧!