2017-03-07 40 views
0
@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); 
    } 
} 

它运作良好。它真的让我困惑。

+0

是您的stockreviewsRepositoryDao与@库注解/ @组件/ @服务? – ByeBye

+0

我试过了,但没有奏效。所以我删除了@ Repository/@ Component/@ Service。 –

回答

1

您是否尝试过注释

stockreviewsRepositoryDao@Repository

Application@EnableJpaRepositories(basePackageClasses = {"stockreviewsRepositoryDao.class"})

相关问题