Spring boot IntelliJ Idea+;无法自动连线。未找到类型为的bean
在我的IntelliJ想法中,我一直看到下面的错误,但是代码在执行过程中运行良好Spring boot IntelliJ Idea+;无法自动连线。未找到类型为的bean,spring-boot,intellij-idea,Spring Boot,Intellij Idea,在我的IntelliJ想法中,我一直看到下面的错误,但是代码在执行过程中运行良好 Could not autowire. No beans of 'PortfolioRequestHandler' type found. less... (Ctrl+F1) Inspection info:Checks autowiring problems in a bean class. 示例代码 我怎样才能摆脱这个?我使用的是IntelliJ Idea ULTIMATE 2018.2您确定Spring
Could not autowire. No beans of 'PortfolioRequestHandler' type found. less... (Ctrl+F1)
Inspection info:Checks autowiring problems in a bean class.
示例代码
我怎样才能摆脱这个?我使用的是IntelliJ Idea ULTIMATE 2018.2您确定Spring Bean的连接正确并且是IDE问题吗
PortfolioRequestHandler
类是否用@Service
、@Component
或@Repository
注释(通过组件扫描进行bean配置)@Configuration
annotated类->在这种情况下,应该有一个方法返回类型为PortfolioRequestHandler
的实例,并用@bean
@springbootest(classes={…}
注释中;请参见下面的示例@springbootest(classes={Application.class,CustomBeanConfig.class})
确保为模块配置了Spring上下文:Try version from如果继续看到错误,但应用程序按预期工作,请使用示例项目在处报告错误。
@ActiveProfiles("test")
@RunWith(SpringRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
@SpringBootTest(classes = {Application.class})
public class PortfolioRequestHandlerTest {
@Autowired
private PortfolioRequestHandler portfolioRequestHandler;
...
...
}
@Configuration
public class CustomBeanConfig {
@Bean
public PortfolioRequestHandler get PortfolioRequestHandler() {
return new PortfolioRequestHandler();
}
}