运行代码报错:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'community.servlet.context-path' in value "${community.servlet.context-path}"
1.发现controll文件没加注解@Controller,添加后报错:html中bean依然爆红,运行代码后报错:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'homeController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'community.servlet.context-path' in value "${community.servlet.context-path}"
UserService中contextPath注入的值为变量server.sevlet.context-path,而不是ommunity.servlet.context-path
在尝试运行代码时遇到了SpringBean的创建异常,具体是userService的注入失败,原因是无法解析community.servlet.context-path的占位符。在添加了@Controller注解后,homeController的依赖仍然不满足,问题依然指向userService,因为UserService中的contextPath注入值应为server.servlet.context-path而非ommunity.servlet.context-path。
3785

被折叠的 条评论
为什么被折叠?



