1
在我的春天啓動的應用程序,我有一個服務於txt
文件,如下寫:NoSuchBeanDefinitionException:無型的排位豆可用
@Service
public class LinksWriterService {
public LinksWriterService(){
//..
}
public void writeToFile(String text) {
//..
}
}
,然後在我的主要方法我已經下文將其稱爲:
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(SeleniumApplication.class, args);
LinksWriterService writer = context.getBean(LinksWriterService.class);
writer.writeToFile("Salmaaaaaaaaaaaaaaaan");
}
但在最後一行它抱怨:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.service.LinksWriterService' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:353)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:340)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1090)
at com.example.demo.SeleniumApplication.main(SeleniumApplication.java:21)
嘗試清理和重新編譯您的項目。 – Berger
這個問題與寫入文件無關 – eis
我希望你的'LinksWriterService' bean沒有被組件掃描。檢查它所在的包是否位於主應用程序類聲明的組件掃描範圍內。 –