为什么在Spring服务实现类中使用不带字符串参数和带字符串参数的@Service
最佳答案
@Service
不带参数有一个默认的服务名称,一般与你的类名相同,但第一个字符小写。
例如,
@Service
class LoadService {}
默认服务名称是loadService
并且@Service(value = "serviceName")
显式指定服务名称。
例如,
@Service(value = "myServiceName")
class LoadService {}
服务名称是myServiceName
来自 spring 文档:
The value may indicate a suggestion for a logical component name, to be turned into a Spring bean in case of an autodetected component.
因此,当一个项目有两个以上名称相同的类并且它们都有@Service
注解时,您应该使用带参数的@Service
。
关于spring - 为什么在 spring 中使用 @Service 以及 @Service ("") 和字符串参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25257371/