'Spring boot Error creating bean with name 'canalRessource' defined in file Unsatisfied dependency expressed through constructor parameter 0
When i run my java app this error occurs : " Error creating bean with name 'canalRessource' defined in file [C:\project\bo\target\classes\fcb\inetum\bo\CanalRessource.class]: Unsatisfied dependency expressed through constructor parameter 0;"
this my 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>2.5.13</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>fcb.inetum</groupId>
<artifactId>bo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>backoffice</name>
<description>backoffice app</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
this is my main app code:
package fcb.inetum.bo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BackofficeApplication {
public static void main(String[] args) {
SpringApplication.run(BackofficeApplication.class, args);
}
}
this my canalressource.java :
package fcb.inetum.bo;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import fcb.inetum.bo.model.canal;
import fcb.inetum.bo.service.canalService;
@RestController
@RequestMapping("/canal")
public class CanalRessource {
private final canalService canalService;
public CanalRessource(canalService canalService) {
this.canalService = canalService;
}
@GetMapping("/all")
public ResponseEntity<List<canal>> getAllCanal() {
List<canal> canals = canalService.FindAllCanal();
return new ResponseEntity<>(canals, HttpStatus.OK);
}
@GetMapping("/find/{canal_codi}")
public ResponseEntity<canal> getCanalById(@PathVariable("canal_codi") String canal_codi) {
canal canal = canalService.findCanalBycanal_codi(canal_codi);
return new ResponseEntity<>(canal, HttpStatus.OK);
}
@PostMapping("/add")
public ResponseEntity<canal> AddCanal(@RequestBody canal canal) {
canal newcanal =canalService.AddCanal(canal);
return new ResponseEntity<>(canal, HttpStatus.CREATED);
}
@PutMapping("/update")
public ResponseEntity<canal> UpdateCanal(@RequestBody canal canal) {
canal newcanal =canalService.UpdateCanal(canal);
return new ResponseEntity<>(canal, HttpStatus.OK);
}
@DeleteMapping("/delete/{canal_codi}")
public ResponseEntity<?> DeleteCanal(@PathVariable("canal_codi") String canal_codi) {
canalService.DeleteCanal(canal_codi);
return new ResponseEntity<>( HttpStatus.OK);
}
}
this is my canal.java
package fcb.inetum.bo.model;
import javax.persistence.*;
import java.io.Serializable;
import java.util.*;
import javax.persistence.Entity;
import javax.persistence.*;
@Entity
@Table(name="canal")
public class canal implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private String codi_canal;
private String nom;
private int id_banc;
private String auto_revisio;
private Date data_alta;
private Date data_modificacio;
private Date data_baixa;
private String id_extern;
private String actiu;
private String email_responsable;
private String usr_alta;
private String usr_modificacio;
private String usr_baixa;
private String canal_pci;
private String password;
private String url_retorn;
private int timeout_3d;
private String reintent_3d_error;
private String url_notificacio;
public canal() {
}
public canal(String codi_canal, String nom, int id_banc, String auto_revisio, Date data_alta, Date data_modificacio,
Date data_baixa, String id_extern, String actiu, String email_responsable, String usr_alta,
String usr_modificacio, String usr_baixa, String canal_pci, String password, String url_retorn,
int timeout_3d, String reintent_3d_error, String url_notificacio) {
this.codi_canal = codi_canal;
this.nom = nom;
this.id_banc = id_banc;
this.auto_revisio = auto_revisio;
this.data_alta = data_alta;
this.data_modificacio = data_modificacio;
this.data_baixa = data_baixa;
this.id_extern = id_extern;
this.actiu = actiu;
this.email_responsable = email_responsable;
this.usr_alta = usr_alta;
this.usr_modificacio = usr_modificacio;
this.usr_baixa = usr_baixa;
this.canal_pci = canal_pci;
this.password = password;
this.url_retorn = url_retorn;
this.timeout_3d = timeout_3d;
this.reintent_3d_error = reintent_3d_error;
this.url_notificacio = url_notificacio;
}
public String getCodi_canal() {
return codi_canal;
}
public void setCodi_canal(String codi_canal) {
this.codi_canal = codi_canal;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public int getId_banc() {
return id_banc;
}
public void setId_banc(int id_banc) {
this.id_banc = id_banc;
}
public String getAuto_revisio() {
return auto_revisio;
}
public void setAuto_revisio(String auto_revisio) {
this.auto_revisio = auto_revisio;
}
public Date getData_alta() {
return data_alta;
}
public void setData_alta(Date data_alta) {
this.data_alta = data_alta;
}
public Date getData_modificacio() {
return data_modificacio;
}
public void setData_modificacio(Date data_modificacio) {
this.data_modificacio = data_modificacio;
}
public Date getData_baixa() {
return data_baixa;
}
public void setData_baixa(Date data_baixa) {
this.data_baixa = data_baixa;
}
public String getId_extern() {
return id_extern;
}
public void setId_extern(String id_extern) {
this.id_extern = id_extern;
}
public String getActiu() {
return actiu;
}
public void setActiu(String actiu) {
this.actiu = actiu;
}
public String getEmail_responsable() {
return email_responsable;
}
public void setEmail_responsable(String email_responsable) {
this.email_responsable = email_responsable;
}
public String getUsr_alta() {
return usr_alta;
}
public void setUsr_alta(String usr_alta) {
this.usr_alta = usr_alta;
}
public String getUsr_modificacio() {
return usr_modificacio;
}
public void setUsr_modificacio(String usr_modificacio) {
this.usr_modificacio = usr_modificacio;
}
public String getUsr_baixa() {
return usr_baixa;
}
public void setUsr_baixa(String usr_baixa) {
this.usr_baixa = usr_baixa;
}
public String getCanal_pci() {
return canal_pci;
}
public void setCanal_pci(String canal_pci) {
this.canal_pci = canal_pci;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUrl_retorn() {
return url_retorn;
}
public void setUrl_retorn(String url_retorn) {
this.url_retorn = url_retorn;
}
public int getTimeout_3d() {
return timeout_3d;
}
public void setTimeout_3d(int timeout_3d) {
this.timeout_3d = timeout_3d;
}
public String getReintent_3d_error() {
return reintent_3d_error;
}
public void setReintent_3d_error(String reintent_3d_error) {
this.reintent_3d_error = reintent_3d_error;
}
public String getUrl_notificacio() {
return url_notificacio;
}
public void setUrl_notificacio(String url_notificacio) {
this.url_notificacio = url_notificacio;
}
@Override
public String toString() {
return "canal {codi_canal=" + codi_canal + ", nom=" + nom + ", id_banc=" + id_banc + ", auto_revisio="
+ auto_revisio + ", data_alta=" + data_alta + ", data_modificacio=" + data_modificacio + ", data_baixa="
+ data_baixa + ", id_extern=" + id_extern + ", actiu=" + actiu + ", email_responsable="
+ email_responsable + ", usr_alta=" + usr_alta + ", usr_modificacio=" + usr_modificacio + ", usr_baixa="
+ usr_baixa + ", canal_pci=" + canal_pci + ", password=" + password + ", url_retorn=" + url_retorn
+ ", timeout_3d=" + timeout_3d + ", reintent_3d_error=" + reintent_3d_error + ", url_notificacio="
+ url_notificacio + "}";
}
}
this is my canalrepo.java
package fcb.inetum.bo.repo;
import java.util.*;
import org.springframework.data.jpa.repository.JpaRepository;
import fcb.inetum.bo.model.canal;
public interface canalrepo extends JpaRepository<canal,String> {
void deleteCanalBycanal_codi(String canal_codi);
Optional<canal> findCanalBycanal_codi(String canal_codi);
}
canalservice.java
package fcb.inetum.bo.service;
import java.util.List;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import fcb.inetum.bo.exceptions.CanalNotFoundException;
import fcb.inetum.bo.model.canal;
import fcb.inetum.bo.repo.canalrepo;
@Service
public class canalService {
private final canalrepo canalrepo;
@Autowired
public canalService(canalrepo canalrepo) {
this.canalrepo = canalrepo;
}
public canal AddCanal(canal canal) {
canal.setCodi_canal(UUID.randomUUID().toString());
return canalrepo.save(canal);
}
public List<canal> FindAllCanal() {
return canalrepo.findAll();
}
public canal UpdateCanal(canal canal) {
return canalrepo.save(canal);
}
public canal findCanalBycanal_codi(String canal_codi) {
return canalrepo.findCanalBycanal_codi(canal_codi)
.orElseThrow(() -> new CanalNotFoundException("Canal Con codi "+canal_codi+" not found"));
}
public void DeleteCanal(String canal_codi) {
canalrepo.deleteCanalBycanal_codi(canal_codi);
}
}
canalnotfound.java
package fcb.inetum.bo.exceptions;
public class CanalNotFoundException extends RuntimeException {
public CanalNotFoundException(String message) {
super(message);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
