我知道这不是一个最好的设计,而只是一个春季新手的想法。
现在我们可以很容易地autowire
在 Spring 框架中方便地相互提供任何服务方法。但是创建服务类的静态工厂方法并到处调用它有什么缺点呢?
这很常见:
@Autowired
CustomerService customerService;
....
AccountDetail ad = customerService.getAccountDetail(accountId, type);
但这也应该有效:
AccountDetail ad = CustomerService.getAccountDetail(accountId, type); //if we make getAccountDetail(String, String) static
那么为什么会有像 autowire 这样的设计呢?它看起来很花哨而且很酷,但是这背后的工作仍然是在另一个服务对象上创建一个服务 bean 实例。
说真的,当春天遍布市场时,很多帖子和文章都在谈论优点和翻新。但它是否能保证更好的性能(比如使用 autowire 而不是 static)?