spring boot 两种方式注入到静态工具类里面

直接上代码

方式1:

//可以换成@Configuration,与@Inject配合使用
@Componentpublic 
class XXUtils { 
        //可以换成@Inject
       @Resource
  private XXXProperties xxxPropertiesAutowired; 

  private static XXXProperties xxxProperties; 

       @PostConstruct 
       public void init() {
              this.xxxPropertiesAutowired = xxxProperties;
       }
}


方式2:zs

@Component

public class UrlUtil {

     private static RRJConfig rrjConfig;

    @Autowired
    public void setRRJConfig(RRJConfig rRJConfig) {
    UrlUtil.rrjConfig = rRJConfig;
    }

你可能感兴趣的:(spring,boot)