在春天定义和注入枚举bean

时间:2017-06-27 04:30:40

标签: java spring enums

我有一些代码如下:

1。 ConsignmentChartsController类:

public class ConsignmentChartsController extends DefaultWidgetController {
    @Autowired
    private PieChartRenderer  pieChartRenderer;
}

2。 PieChartRenderer接口和DefaultPieChartRenderer类

public interface PieChartRenderer {
    void render(Charts chart, final Map<String, Number> chartData);
}
public class DefaultPieChartRenderer implements PieChartRenderer {
   @Autowired
   private List<ChartColor> colors;
    ...........
   @Required
   public void setColors(final List<ChartColor> colors) {
     this.colors = colors;
   }

}

3。枚举类:

public enum ChartColor {
   PURPLE() {
      @Override
      public Color getColor() {
         return (new Color("rgba(218,114,218,1)"));
      }
   },
   BLUE() {
      @Override
      public Color getColor() {
        return (new Color("rgba(114,166,218,1)"));
      }
    },
    public abstract Color getColor();

    }

我想在spring.xml文件中定义这些bean。如何定义ChartColor bean然后将其注入DefaultPieChartRenderer,并定义DefaultPieChartRenderer bean并注入ConsignmentChartsController

0 个答案:

没有答案