Optional Spring bean references

后端 未结 5 2133
逝去的感伤
逝去的感伤 2020-12-03 17:22

In my application I am using ContextLoaderListener to load context files from many jars using:


    contextConfigLocat         


        
5条回答
  •  时光说笑
    2020-12-03 17:28

    With recent versions of Spring (tested with spring 4.1) and Java Configuration and Java 8, you can use Optional in parameters, and are only autowired if available.

    @Autowired
    public MyApplication(Optional maybeObject) {
        // do something with the optional autowired
    }
    

提交回复
热议问题