@Controller
@EnableAutoConfiguration
public class ControllerShowInfo
{
@RequestMapping("/")
public String rawPage()
{
return "rawPage";
}
@Autowired
stockreviewsRepositoryDao repository;
@RequestMapping("/getBaseInfo")
@ResponseBody
public JSONArray getReviewsInfo()
{
JSONArray jsonArray = new JSONArray();
for (stockreviewsBean reviewBean : repository.findAll())
{
jsonArray.put(reviewBean);
System.out.println(reviewBean.getTitle());
}
return jsonArray;
}
public static void main(String[] args) throws Exception
{
SpringApplication.run(ControllerShowInfo.class, args);
}
}
這是控制器層。spring boot,沒有發現依賴性的bean類型:預計至少有1個bean符合此依賴關係的自動導向候選項
public interface stockreviewsRepositoryDao extends CrudRepository<stockreviewsBean,String>
{
}
這是道層。當我運行ControllerShowInfo.class時,我使用了 。這裏有一個問題如下:
org.springframework.beans.factory.UnsatisfiedDependencyException:錯誤創建名爲「controllerShowInfo」豆:不滿意依賴通過現場「倉庫」表示:式中沒有合格豆[com.yxzh .mapper.stockreviewsRepositoryDao]找到依賴關係[com.yxzh.mapper.stockreviewsRepositoryDao]:預計至少有1個bean有資格作爲這個依賴關係的autowire候選。依賴註釋:{@ org.springframework.beans.factory.annotation.Autowired(required = true)};嵌套異常是org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到符合[com.yxzh.mapper.stockreviewsRepositoryDao]類型的[com.yxzh.mapper.stockreviewsRepositoryDao]類型的合格bean:期望至少1個符合自動裝配候選爲此依賴。依賴註釋:
但是當我再跑的.class
@SpringBootApplication
public class Application
{
public static void main(String[] args) throws Exception
{
SpringApplication.run(Application.class, args);
}
}
和實施CommmandLineRunner
@Component
public class DataInitialization implements CommandLineRunner{
@Autowired
stockreviewsRepositoryDao repository;
@Override
public void run(String... args) throws Exception
{
System.out.println("-------------------------------");
int count=0;
for (stockreviewsBean reviewBean : repository.findAll())
{
count++;
System.out.println(reviewBean.getTitle());
}
System.out.println(count);
}
}
它運作良好。它真的讓我困惑。
是您的stockreviewsRepositoryDao與@庫註解/ @組件/ @服務? – ByeBye
我試過了,但沒有奏效。所以我刪除了@ Repository/@ Component/@ Service。 –