相关疑难解决方法(0)

@Value - >无法将'java.lang.String'类型的值转换为必需类型'java.lang.Integer'

美好的一天,我正在使用Spring 4.1.1.RELEASE开发Web应用程序.所有Spring配置都是使用注释完成的,除了一件事外它工作正常:

  • 我在项目中有这些行的config.properties文件

    cases.caseList.filter=test
    cases.caseList.numberOfCasesPerPage=50
    
    Run Code Online (Sandbox Code Playgroud)
  • 我有一个配置类

    @Configuration
    @ComponentScan(basePackageClasses={CaseConfig.class})
    @PropertySource(value = "classpath:config.properties")
    public class CasesModuleTestContextConfig { ... }
    
    Run Code Online (Sandbox Code Playgroud)
  • 另一堂课

    @Component
    public class HttpRequestParamsToPaginationParams extends AbstractConverter<Map<String, String>, PaginationParams> {
    
        @Value("${cases.caseList.filter}")
        private String filter;
    
        @Value("${cases.caseList.numberOfCasesPerPage}")
        private Integer count;
    
        ...
    }
    
    Run Code Online (Sandbox Code Playgroud)

属性'过滤器'的值是从属性资源中成功注入的.但我在财产'计数'上得到例外:

     13:58:45.274 [main] WARN  o.s.c.s.GenericApplicationContext - Exception encountered during context initialization - cancelling refresh attempt 
     org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cz.pokus.core.test.config.ConversionServiceTestConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.List cz.pokus.core.test.config.ConversionServiceTestConfig.converterList; nested exception is org.springframework.beans.factory.BeanCreationException: Error …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc

16
推荐指数
2
解决办法
6万
查看次数

标签 统计

java ×1

spring ×1

spring-mvc ×1