Home > Enterprise >  Error creating bean with name 'taxeIRImpl'
Error creating bean with name 'taxeIRImpl'

Time:03-25

When I try to run my project I get this error :

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'taxeIRImpl': Unsatisfied dependency expressed through field 'taxeIRDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'taxeIRDao' defined in com.example.taxe.dao.TaxeIRDao defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract com.example.taxe.bean.TaxeIR com.example.taxe.dao.TaxeIRDao.findbyMoisAndAnneAndEmploye(int,int,com.example.taxe.bean.Employe)! Reason: Failed to create query for method public abstract com.example.taxe.bean.TaxeIR com.example.taxe.dao.TaxeIRDao.findbyMoisAndAnneAndEmploye(int,int,com.example.taxe.bean.Employe)! No property findbyMois found for type TaxeIR!; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.example.taxe.bean.TaxeIR com.example.taxe.dao.TaxeIRDao.findbyMoisAndAnneAndEmploye(int,int,com.example.taxe.bean.Employe)! No property findbyMois found for type TaxeIR!   at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659) ~[spring-beans-5.3.15.jar:5.3.15]   at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) ~[spring-beans-5.3.15.jar:5.3.15]  at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.15.jar:5.3.15]  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.15.jar:5.3.15]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[spring-beans-5.3.15.jar:5.3.15]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) ~[spring-beans-5.3.15.jar:5.3.15]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar:5.3.15]   at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar:5.3.15]     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar:5.3.15]     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar:5.3.15]  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15]    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.15.jar:5.3.15]     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.15.jar:5.3.15]  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.15.jar:5.3.15]  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.3.jar:2.6.3]  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-2.6.3.jar:2.6.3]    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:414) ~[spring-boot-2.6.3.jar:2.6.3]     at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.3.jar:2.6.3]    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.6.3.jar:2.6.3]   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.6.3.jar:2.6.3]   at com.example.taxe.ProjetTaxeIrApplication.main(ProjetTaxeIrApplication.java:10) ~[classes/:na]

Here are my beans :

@Entity
public class TaxeIR {
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private int mois;
    private int annee;
    @ManyToOne
    private Employe employe;
    @ManyToOne
    private Employeur employeur;
    private double salaire;
    private double cotisation;
    private String employeICE;
    @ManyToOne
    private User user;
@Entity
public class Employe {
    @Id @GeneratedValue (strategy = GenerationType.IDENTITY)
    private Long id;
    private String cin;
    private String nom;
    private String prenom;
    private double salaire;
    @ManyToOne
    private Employeur employeur;
@Repository
public interface TaxeIRDao extends JpaRepository<TaxeIR, Long> {
    TaxeIR findbyMoisAndAnneAndEmploye(int mois,int annee,Employe employe);
    List<TaxeIR> findByEmployeCin(String cin);
    List<TaxeIR> findByUserLogin(String login);
    List<TaxeIR> findByEmployeICE(String rc);
}

@Service
public class TaxeIRImpl implements TaxeIRService {
    @Autowired
    TaxeIRDao taxeIRDao;

    @Override
    public List<TaxeIR> findByEmployeCin(String cin) {
        return findByEmployeCin(cin);}

    @Override
    public List<TaxeIR> findByUserLogin(String login) {
        return findByUserLogin(login);}

    @Override
    public TaxeIR findbyMoisAndAnneAndEmploye(int mois, int annee, Employe employe) {
        return findbyMoisAndAnneAndEmploye(mois,annee,employe);}

    @Override
    public List<TaxeIR> findByEmployeICE(String rc) {
        return taxeIRDao.findByEmployeICE(rc);}
    @Override
    public int save(TaxeIR taxeIR) {
        TaxeIR taxeIRfound = findbyMoisAndAnneAndEmploye(taxeIR.getMois(),taxeIR.getAnnee(),taxeIR.getEmploye());
        if(taxeIRfound!=null)
            return -1;
        else {
            taxeIRDao.save(taxeIR);
            return 1;
        }
    }
}
@RestController
@RequestMapping("/api/v1/taxeIR")
public class TaxeIRWs {
    @Autowired
    private TaxeIRImpl taxeIRImpl;
    @GetMapping("/cin/{cin}")
    public List<TaxeIR> findByEmployeCin(@PathVariable String cin) {
        return taxeIRImpl.findByEmployeCin(cin);
    }
    @GetMapping("/login/{login}")
    public List<TaxeIR> findByUserLogin(@PathVariable String login) {
        return taxeIRImpl.findByUserLogin(login);
    }
    @GetMapping("/mois/{mois}/annee/{annee}")
    public TaxeIR findbyMoisAndAnneAndEmploye(@PathVariable int mois,@PathVariable int annee,@RequestBody  Employe employe) {
        return taxeIRImpl.findbyMoisAndAnneAndEmploye(mois, annee, employe);
    }

    @GetMapping("/rc/{rc}")
    public List<TaxeIR> findByEmployeICE(@PathVariable String rc) {
        return taxeIRImpl.findByEmployeICE(rc);
    }
    @PostMapping("/")
    public int save(@RequestBody TaxeIR TaxeIR) {
        return taxeIRImpl.save(TaxeIR);
    }
}

I reviewed all my files and I can't seem to find the error myself, like I said in the title I am a beginner and I would like some help.

The expected result is for it to just run and for me to be able to interact with it through Postman

CodePudding user response:

It's a silly little mistake, but the devil's in de detail.

You need to use CamelCasing for this method:

TaxeIR findbyMoisAndAnneAndEmploye(int mois,int annee,Employe employe);

You have 'findby' and it needs to be 'findBy'. Capital B.

See this answer if you want further details: Spring Data JPA - "No Property Found for Type" Exception

  • Related