shiqing0115 2020-04-01 10:50 采纳率: 50%
浏览 813

注解里怎么从配置文件里读出int类型的配置,默认读出来的都是String的

下面代码里的 maxInactiveIntervalInSeconds = 3000, 3000怎么写到配置里去,并且拿到的书int类型

@ComponentScan({"com.banda.admin"})
@Configuration
@EnableScheduling
@Import({CommonImportConfig.class})
@EnableRedisHttpSession(
maxInactiveIntervalInSeconds = 3000,
redisNamespace = "spring.session.redis.namespace")
public class AdminConfig extends WebMvcConfigurerAdapter {
.
.
.
}

  • 写回答

1条回答 默认 最新

  • Json-Huang 2020-04-01 13:48
    关注

    按如下步骤试试:
    1、在类路经下增加个配置文件如config.properties,配置如下:
    maxInactiveIntervalInSeconds = 3000

    2、需要获取配置的类加上注解

    @PropertySource(value = {"classpath:/config.properties"})

    3、@Value("${maxInactiveIntervalInSeconds}”)注解获取配置,定义变量类型为Integer即可

    @Value("${maxInactiveIntervalInSeconds}")
    private Integer maxInactiveIntervalInSeconds;

    评论

报告相同问题?