gpt4 book ai didi

java - 创建 URL 中定义的名称为 'repositorySearchController' 的 bean 时出错

转载 作者:行者123 更新时间:2023-12-04 08:19:22 26 4
gpt4 key购买 nike

目前我正在尝试运行我的 Spring Boot 应用程序。我按照教程:https://www.youtube.com/watch?v=BtUdl9pZwR0
不幸的是我得到一个错误:
org.springframework.beans.factory.UnsatisfiedDependencyException:在 URL [jar:file:/C:/Users//.m2/repository/org/springframework/data/spring-data-rest- 中定义名称为“repositorySearchController”的 bean 创建错误webmvc/3.3.2.RELEASE/spring-data-rest-webmvc-3.3.2.RELEASE.jar!/org/springframework/data/rest/webmvc/RepositorySearchController.class]:通过构造函数参数0表示的不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义名称为“pagedResourcesAssembler”的 bean 创建时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.web.PagedResourcesAssembler]:工厂方法“pagedResourcesAssembler”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义的名称为“pageableResolver”的 bean 时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.web.HateoasPageableHandlerMethodArgumentResolver]:工厂方法“pageableResolver”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义的名称为“sortResolver”的 bean 时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.web.HateoasSortHandlerMethodArgumentResolver]:工厂方法“sortResolver”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义名称为“repositoryRestConfiguration”的 bean 创建错误:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.rest.core.config.RepositoryRestConfiguration]:工厂方法“repositoryRestConfiguration”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义的名称为“repositories”的 bean 时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.repository.support.Repositories]:工厂方法“存储库”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为 'userRepository' 的 bean 时出错'映射上下文';嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“jpaMappingContext”的 bean 时出错:调用 init 方法失败;嵌套异常是 org.hibernate.AnnotationException:没有为实体指定标识符:com.Product.ProductExcelController

public class ExcelExporter {
private XSSFWorkbook workbook;
private XSSFSheet sheet;

private List<Product> listProducts;

public ExcelExporter(List<Product> listProducts) {
this.listProducts = listProducts;
workbook = new XSSFWorkbook();
sheet = workbook.createSheet("Products");
}

private void writeHeaderRow(){
Row row = sheet.createRow(0);

CellStyle style = workbook.createCellStyle();
XSSFFont font = workbook.createFont();
font.setBold(true);
font.setFontHeight(16);
style.setFont(font);

Cell cell = row.createCell(0);
cell.setCellValue("Product ID");
cell.setCellStyle(style);

cell = row.createCell(1);
cell.setCellValue("Name");
cell.setCellStyle(style);

cell = row.createCell(2);
cell.setCellValue("Kategorie");
cell.setCellStyle(style);

cell = row.createCell(3);
cell.setCellValue("Text");
cell.setCellStyle(style);

cell = row.createCell(4);
cell.setCellValue("Location");
cell.setCellStyle(style);
}
private void writeDataRows(){
int rowCount = 1;

for (Product Products : listProducts) {
Row row = sheet.createRow(rowCount);

Cell cell = row.createCell(0);
cell.setCellValue(Product.getId());

cell = row.createCell(1);
cell.setCellValue(Product.getName());

cell = row.createCell(2);
cell.setCellValue(Product.getCategory());

cell = row.createCell(3);
cell.setCellValue(Product.getText());

cell = row.createCell(4);
cell.setCellValue(Product.getLocation());

}
}
public void export(HttpServletResponse response) throws IOException {
writeHeaderRow();
writeDataRows();

ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
workbook.close();
outputStream.close();
}
}
Product:
@EnableJpaRepositories
@Entity
@Service
public class Product {
private static Long id;
private static String name;
private static String category;
private static String text;
private static String location;

public Product() {}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public static Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}

public static String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public static String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public static String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public static String getLocation() { return location; }

public void setLocation(String location) {
this.location = location;
}
}
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.0</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-security</artifactId>-->
<!-- </dependency>-->

<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.0.0</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>8.0.22</version>
</dependency>
<dependency>
<groupId>net.sf.supercsv</groupId>
<artifactId>super-csv</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>

<!-- <dependency>-->
<!-- <groupId>org.springframework.security</groupId>-->
<!-- <artifactId>spring-security-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我究竟做错了什么?
编辑:
这是更多可能有用的代码: ProductService
@Service
@Transactional
public class ProductService {

@Autowired
public ProductRepository repo;

public List<Product> listAll() {
return repo.findAll();
}

public void save(Product product) {
repo.save(product);
}

public Product get(long id) {
return repo.findById(id).get();
}

public void delete(long id) {
repo.deleteById(id);
}
}
ProductRepository
public interface ProductRepository extends JpaRepository<Product, Long> {

}

最佳答案

ExcelExporter 应使用 @RestController 进行注释。标签。
如果您想使用带有 @Service 注释的服务标签,您应该使用您想要的任何注入(inject)或使用 @Autowired 注释的服务注入(inject)服务在您的 Controller 类中。
由于我的声誉,无法添加评论,而您没有提及。

关于java - 创建 URL 中定义的名称为 'repositorySearchController' 的 bean 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65564178/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com