Spring - using static final fields (constants) for bean initialization

前端 未结 5 1000
轻奢々
轻奢々 2020-12-07 17:07

is it possible to define a bean with the use of static final fields of CoreProtocolPNames class like this:




        
5条回答
  •  不知归路
    2020-12-07 17:43

    One more example to add for the instance above. This is how you can use a static constant in a bean using Spring.

    
      
        
      
    
    
    package org.example;
    
    public class Bar {
      public static String myValue = "SOME_CONSTANT";
    }
    
    package someorg.example;
    
    public class Foo {
        String someOrgValue; 
        foo(String value){
            this.someOrgValue = value;
        }
    }
    

提交回复
热议问题