我已经创建了一个简单的单元测试,但是IntelliJ错误地将它突出显示为红色。将其标记为错误
没有豆子?
如你所见,它通过了测试?所以它一定是自动连接的?
我已经创建了一个简单的单元测试,但是IntelliJ错误地将它突出显示为红色。将其标记为错误
没有豆子?
如你所见,它通过了测试?所以它一定是自动连接的?
当前回答
我只能使用@EnableAutoConfiguration来解决它,但是这个错误没有功能上的影响。
其他回答
检查您是否在服务类中遗漏了@Service注释,我就是这种情况。
我使用的是spring-boot 2.0和intellij 2018.1.1终极版,我也遇到了同样的问题。
我通过在主应用程序类中放置@EnableAutoConfiguration来解决这个问题
@SpringBootApplication
@EnableAutoConfiguration
class App{
/**/
}
你需要做的就是添加
AppConfiguration.java中的@ComponentScan("package/include/your/annotation/component")
因为我认为你的AppConfiguraion.java的包比你的注释组件(@Service, @Component…)的包更深,
比如“package/include/your/annotation/component/deep /config”。
我在spring引导应用程序中解决这个问题的方法是打开spring应用程序上下文,并手动为缺失的自动连接bean添加类!
(通过项目结构菜单或弹簧工具窗口访问…编辑“Spring Application Context”)
因此,SpringApplicationContext不仅仅包含我的ExampleApplication spring配置,它还包含了缺失的Bean:
SpringApplicationContext:
ExampleApplication.java MissingBeanClass.java
et voilà:错误信息消失!
您是否检查过在服务实现之上使用了@Service注释? 这对我很管用。
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserServices {}