Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法在spring引导中创建bean_Java_Spring_Spring Boot - Fatal编程技术网

Java 无法在spring引导中创建bean

Java 无法在spring引导中创建bean,java,spring,spring-boot,Java,Spring,Spring Boot,我明白了 创建名为“listsServiceImpl”的bean时出错:通过字段“listRepo”表示的未满足的依赖关系 每次我运行我的项目时,我都会遇到这个错误 ListRepository.java package com.test.example.repo; import org.springframework.data.repository.CrudRepository; import com.test.example.entity.Lists; public interf

我明白了

创建名为“listsServiceImpl”的bean时出错:通过字段“listRepo”表示的未满足的依赖关系

每次我运行我的项目时,我都会遇到这个错误

ListRepository.java

package com.test.example.repo;   
import org.springframework.data.repository.CrudRepository; 
import com.test.example.entity.Lists;

public interface ListsRepository extends CrudRepository<Lists,String>{
  }
列表服务impl

package com.test.example.service;
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Service;
import com.test.example.entity.Lists;
import com.test.example.repo.ListsRepository;

@Service 
public class ListsServiceImpl implements ListsService{

 @Autowired     
 private ListsRepository listRepo;

 @Override  
 public void create(Lists list) {       
         listRepo.save(list);   
 }

  @Override     
  public boolean checkListName(String listName, String userId) {        
      // TODO Auto-generated method stub        
     return false;  
    } 
}

添加

@组件扫描(“com.test.example”)


在您的主应用程序类中。

只需将
@EnableJpaRepositories
注释添加到您的配置类中。

所有内容都在不同的包中,Spring Boot将只扫描
@SpringBootApplication
注释类所在的包中的内容。还建议将此类放在顶级包中,即
com.test.example
中,而不是该类的子包中。这样,它将扫描所有其他软件包,并启用诸如springdatarepositories.package.com.test.example;导入org.springframework.boot.SpringApplication;导入org.springframework.boot.autoconfigure.springboot应用程序;导入org.springframework.context.annotation.ComponentScan@SpringBootApplication@ComponentScan(“com.test”)公共类exploreApplication{public static void main(String[]args){SpringApplication.run(exploreApplication.class,args);}}我已经启用了它,我正在使用这个@EnableCouchbaseRepositories(basePackages={“com.test.example.repo”})在listsservicepimpl.java中将ListsRepository引用从listRepo更改为ListsRepository
package com.test.example.service;
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Service;
import com.test.example.entity.Lists;
import com.test.example.repo.ListsRepository;

@Service 
public class ListsServiceImpl implements ListsService{

 @Autowired     
 private ListsRepository listRepo;

 @Override  
 public void create(Lists list) {       
         listRepo.save(list);   
 }

  @Override     
  public boolean checkListName(String listName, String userId) {        
      // TODO Auto-generated method stub        
     return false;  
    }