{@org.springframework.beans.factory.annotation.Autowired(required=true)}
1、运行测试方法出下面的情况
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
'com.nowcoder.community.CommunityApplicationTests': Unsatisfied dependency expressed through field 'simpleDateFormat';
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
'java.text.SimpleDateFormat' available: expected at least 1 bean which qualifies as autowire
candidate. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
2、解决方案
原本的测试方法
@Autowired
在之后加上required = false,就是改为
@Autowired(required = false)
就可以解决这个问题