在服务层中制作静态方法有什么坏处 -- Spring 3
2022-09-03 12:26:09
我知道这不是一个最好的设计,而只是一个春天新手的想法。
现在我们可以轻松地在Spring框架中方便地将任何服务方法彼此联系起来。但是,创建服务类的静态工厂方法并在所有位置调用它的缺点是什么?autowire
这是很常见的,就像这样:
@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而不是静态)?