Inject bean into enum

前端 未结 8 2055
误落风尘
误落风尘 2020-11-30 02:01

I have the DataPrepareService that prepare data for reports and I have an Enum with report types, and I need to inject ReportService into Enum or have access to ReportServic

8条回答
  •  庸人自扰
    2020-11-30 02:58

    Just pass it to the method manually

    public enum ReportType {
    
        REPORT_1("name", "filename"),
        REPORT_2("name", "filename"),
        REPORT_3("name", "filename")
    
        public abstract Map getSpecificParams();
    
        public Map getCommonParams(DataPrepareService  dataPrepareService){
            // some code that requires service
        }
    }
    

    As long as you call the method only from managed beans, you can inject it in these beans and pass the reference to the enum on each call.

提交回复
热议问题