当前位置: 首页 > 知识库问答 >
问题:

创建URL中定义的名称为“Repository SearchController”的bean时出错

柯建业
2023-03-14
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();
    }
}
@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;
    }
}
<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>
@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);
    }
}
public interface ProductRepository extends JpaRepository<Product, Long> {

}

暂时还没有答案

 类似资料:
  • 问题内容: 我将所有的XML Spring配置都转换为Java代码配置,但是由于我有一个丑陋的异常,所以我无法运行我的所有测试(它们之前都曾进行过测试): 这是我的测试课: 和我的: 我在测试课上尝试了推子,但这没用。该项目是Spring MVC项目,但是现在我仅测试服务层,所以为什么要在我的课程上放置该注释?即使有了该注释,也会出现另一个错误。那么,这里发生了什么? 问题答案: 您的配置很好,除

  • 问题内容: 我正在使用Springframework和Tomcat创建一个简单的REST服务。响应应该像{“ id”:“ 101”,“ name”:“ Ram”}之类的json中。每次运行时,出现以下错误 从这里开始,以下是我的Java代码和xml文件。 POM.xml web.xml front-controller-servlet.xml json / User.java json / Use

  • 当我尝试启动应用程序时,我得到以下消息: “不满意的依赖关系”异常:创建名称为“产品服务”的 Bean 时出错 [C:\Users\Acasa\0 SDA\0 Proiecte 实践\attentive2细节\目标\类\com\示例\attentive2细节\服务\产品服务.class]:通过构造函数参数 0 表示的不满意的依赖关系;嵌套的异常是组织.springframework.bean.fa

  • 我使用Eclipse Juno 4.2.2并通过Eclipse Marketplace安装了Worklight V6.0 Developer Eition。 我在Tomcat7和Oracle11g上运行Worklight V6.0。 Tomcat的web.xml worklight.properties wl.db.type=oracle wl.db.url=jdbc:oracle:thin:@l

  • 当我试图运行我的项目时,我遇到了以下错误: 这是我的豆子: 我查看了我所有的文件,我自己似乎找不到错误,就像我在标题中所说的,我是初学者,我需要一些帮助。 预期的结果是让它运行,让我能够通过邮递员与它互动

  • 问题内容: 问题: 我正在为在类中执行方法创建切入点。该类是控制器类,由注解@Controller表示,因此对于方面所要求的相同,不需要bean。我附加了dispathcher servlet代码,方面和控制器类。有人可以识别出问题所在。 DISPATCHER SERVLET : 方面: 控制器类别: 控制台错误: 问题答案: 这是Spring AOP中的限制。当你使用AspectJ切入点将方面编