Error Creating Bean: Post processing of merged bean definition filed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productImplementJPA' defined in file [D:\Tech Projects\API Development\FoodSense\FoodSenseAPI\target\classes\com\foodsense\demo\dao\ProductImplementJPA.class]: Post-processing of merged bean definition failed

Encountered an issue during application startup where the bean creation fails with the error message ‘Error Creating Bean: Post processing of merged bean definition failed,’ seemingly indicating a problem in the bean merging process; seeking guidance and potential solutions to diagnose and resolve this specific error in my Spring application configuration, as attempts to rectify it through conventional means have been unsuccessful. When i try to use JPA the bean creation is failed. Please help me solve the error.

Product.java

package com.foodsense.demo.model;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.JoinColumn;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="product")
public class Product {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @SequenceGenerator(name = "product_id")
    private long productId;

    @Column(name="product_name")
    private String productName;

    @Column(name="product_stock")
    private int productStock;

    @Column(name="product_unit_price")
    private double productUnitPrice;

    @Column(name="product_description")
    private String productDescription;

    @Column(name="product_is_food")
    private boolean isFood;

    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="seller_id")
    @Column(name="seller_id")
    private Seller seller;

    @Column(name="image_url")
    private String imageUrl;

    public Product(){}

    public Product(long productId, String productName, int productStock, double productUnitPrice, boolean isFood, String productDescription, String imageUrl, Seller seller){
        setProductId(productId);
        setProductName(productName);
        setProductStock(productStock);
        setProductUnitPrice(productUnitPrice);
        setIsFood(isFood);
        setProductDescription(productDescription);
        setImageUrl(imageUrl);
        setSeller(seller);
    }

    public Product(String productName, int productStock, double productUnitPrice, boolean isFood, String productDescription, String imageUrl){
        setProductName(productName);
        setProductStock(productStock);
        setProductUnitPrice(productUnitPrice);
        setIsFood(isFood);
        setProductDescription(productDescription);
        setImageUrl(imageUrl);
    }

    public long getProductId(){
        return productId;
    }

    public void setProductId(long productId){
        this.productId = productId;
    }

    public String getProductName(){
        return productName;
    }

    public void setProductName(String productName){
        this.productName = productName;
    }

    public int getProductStock(){
        return productStock;
    }

    public void setProductStock(int productStock){
        this.productStock = productStock;
    }

    public double getProductUnitPrice(){
        return productUnitPrice;
    }

    public void setProductUnitPrice(double productUnitPrice){
        this.productUnitPrice = productUnitPrice;
    }

    public boolean getIsFood(){
        return isFood;
    }

    public void setIsFood(boolean isFood){
        this.isFood = isFood;
    }

    public String getProductDescription(){
        return productDescription;
    }

    public void setProductDescription(String productDescription){
        this.productDescription = productDescription;
    }

    public String getImageUrl(){
        return imageUrl;
    }

    public void setImageUrl(String imageUrl){
        this.imageUrl = imageUrl;
    }

    public Seller getSeller(){
        return seller;
    }

    public void setSeller(Seller seller){
        this.seller = seller;
    }

    public void showSellerInfo(Seller seller){
        System.out.println("Seller ID   : " + seller.getSellerId());  
        System.out.println("Full Name   : " + seller.getFullName()); 
        System.out.println("Phone Number: " + seller.getphone_number());
        System.out.println("Address     : " + seller.getAddress());
    }

    public void updateProductStock(int quantity){
        this.productStock +=  quantity;
    }
}

ProductJPARepo,java

package com.foodsense.demo.repository;

import com.foodsense.demo.model.Product;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ProductJPARepo extends JpaRepository<Product, Long>{}

ProductImplementJPA.java

package com.foodsense.demo.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.foodsense.demo.model.Product;
import com.foodsense.demo.repository.ProductJPARepo;

@Service
public class ProductImplementJPA {

    @Autowired
    private ProductJPARepo productJPARepo;
    
    public ProductImplementJPA(){}

    public List<Product> findAllProduct(){
        return productJPARepo.findAll();
    }
}

ProductController.java

@GetMapping("/get")
public ResponseEntity<List<Product>> findAllProduct(){
    log.info("Fetching all product...");
    List<Product> products = productService.findAllProduct();
    if (!products.isEmpty()) {
        log.info("Found all products: {}", products.size());
        return ResponseEntity.ok(products);
    } else {
        log.warn("No product found in the database");
        return ResponseEntity.status(HttpStatus.NO_CONTENT).body(products);
    }
}

Main.java

package com.foodsense.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Main {
    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
    }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.0</version>
        <relativePath/>
    </parent>
    <groupId>com.foodsense</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>spring-cloud-azure-starter-storage-blob</artifactId>
            <version>5.8.0</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.13.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

  • You are mixing @GeneratedValue(strategy = GenerationType.IDENTITY) and @SequenceGenerator. Im not sure about this. You are also mixing @Column et @JoinColumn : drop the @Column

    – 

Leave a Comment