Spring Condition not able to read value from property file

后端 未结 4 890
耶瑟儿~
耶瑟儿~ 2021-01-11 13:24

I am trying to implement Spring Condition org.springframework.context.annotation.Conditionas follows:

public class APIScanningDecisionMaker impl         


        
4条回答
  •  迷失自我
    2021-01-11 13:55

    this works fine for me

    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        try {
            InputStream i = conditionContext.getResourceLoader().getResource("prop.file").getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(i));
            StringBuilder out = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                out.append(line);
            }
            System.out.println(out.toString());
    
        } catch (IOException e) {
            e.printStackTrace();
        }
    
        return true;
    }
    

提交回复
热议问题