今天研究了一下静态方法调用非静态的方法,在java中普遍会想到的方法
比如A类中有个a方法,B类中有个b方法,在a方法中new B(类).b就可以调用了
但是在ssm整合框架使用这种思想需要注意一些东西看下面我的代码
@Controller
@RequestMapping(value = "${adminPath}/sys/trafficMeasurementFactory")
public class TrafficMeasurementFactory {
private static TrafficMeasurementService trafficMeasurementService0;
@Autowired
private TrafficMeasurementService trafficMeasurementService;
@PostConstruct
public void initStaticService(){
trafficMeasurementService0 = this.trafficMeasurementService;
}
/**
* 这个方法在iReport的DataResource配置时也会用到
* 必须是静态方法 static
*/
@RequestMapping(value = "list")
public static Collection<TrafficMeasurementType> createBeanCollection() {
// TrafficMeasurementFactory trafficMeasurementFactory = new TrafficMeasurementFactory();
Collection<TrafficMeasurementType> beanCollection = new TrafficMeasurementFactory().getTrafficMeasurementServiceList();
return beanCollection;
}
public List<TrafficMeasurementType> getTrafficMeasurementServiceList(){
List<TrafficMeasurementType> beanCollection = trafficMeasurementService0.export();
return beanCollection;
}
}
参考http://*.com/questions/11392692/autowired-in-static-classes
走到这里相信大家也都看懂了,祝好运