spring bean的bean ID是什么实现接口
当为类 MyBean,bean id是,myBean但是
@Servicepublic class ProfileServiceImpl implements ProfileService
当我尝试以@profileService百里香形式访问Bean时,出现以下错误。
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'profileService' is defined一直以来,我一直在使用该bean autowiring作为控制器。但目前,我需要从中访问此文件thymeleaf。
我的百里香代码段
<div th:unless="${@profileService.isMe(user)}">回答:
当Spring通过@Service或@Component批注创建Bean定义时,默认情况下,它将通过小写类名的首字母来为Bean创建一个ID。如果要覆盖该行为,则可以在注释中提供备用ID,例如。@Service(“
profileService”)。
关于您正在使用存储库的内容-默认情况下,Spring通过在存储库接口名称后附加“
Impl”来寻找存储库的自定义实现。如果找到它,则不会创建默认实现。所以,如果你有UserRepositoryImpl extends
UserRepository,而不是UserRepositoryImpl extends
DatatablesCriteriasRepository比Spring不会创建userRepository豆。另外,如果将@NoRepositoryBean注释添加到UserRepository接口,则将禁止创建userRepositoryBean。
但是,UserRepositoryImpl确实应该执行UserRepository。如果它确实是要扩展的DatatablesCriteriasRepository,则应该命名DatatablesCriteriasRepositoryImpl。有UserRepsitoryImpl延长DatatablesCriteriasRepository是设计有问题的迹象。
以上是 spring bean的bean ID是什么实现接口 的全部内容, 来源链接: utcz.com/qa/414127.html

