【问题标题】:Error creating bean with name 'clienteRestController': Unsatisfied dependency expressed through field 'clientService';创建名称为“clienteRestController”的 bean 时出错:通过字段“clientService”表示的依赖关系不满足;
【发布时间】:2019-10-11 11:23:10
【问题描述】:

创建名为“clienteRestController”的 bean 时出错:通过字段“clientService”表达的依赖关系不满足。

创建名为“clientServiceImpl”的 bean 时出错:通过字段“clientDao”表达的依赖关系不满足。

创建名为“IClienteDao”的 bean 时出错:调用 init 方法失败。

嵌套异常是 java.lang.IllegalArgumentException:不是托管类型:类 java.lang.Package

我正在使用带有 MySQL 数据库的 Spring Boot 项目的 Eclipse,当我运行该项目时,我看到了这个错误,我在堆栈溢出中看到了一些解决方案,但没有奏效,任何人都可以帮忙,谢谢

@Entity
@Table(name = "package")
public class Package implements Serializable{

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;

private int count;

@Column(precision=18, scale=2) /** Number (16, 2) **/
private double price;

@Column(name = "createAt")
@Temporal(TemporalType.TIMESTAMP)
private Date createAt;


public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public String getName() {
    return name;
}

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

public int getCount() {
    return count;
}
public void setCount(int count) {
    this.count = count;
}
public double getPrice() {
    return price;
}

public void setPrice(double price) {
    this.price = price;
}
public Date getCreateAt() {
    return createAt;
}
public void setCreateAt(Date createAt) {
    this.createAt = createAt;
}
private static final long serialVersionUID = 1L;

}

控制器“ClienteRestController”:

@CrossOrigin(origins = {"http://localhost:4200"})
@RestController
@RequestMapping("/apiHorsesClub")
public class ClienteRestController {

@Autowired
private IClienteService clientService;

@GetMapping("clients")
public List<Package> index()
{
    return clientService.findAll();
}

}

DAO 层“clientDao”:

public interface IClienteDao extends CrudRepository<Package, Long>{
}

服务层“IClienteService”: 公共接口 IClienteService {

public List<Package> findAll();

}

实现服务“ClientServiceImpl”:

@Service
public class ClientServiceImpl implements IClienteService {

@Autowired
private IClienteDao clientDao;

@Override
@Transactional(readOnly = true)
public List<Package> findAll() {
    return (List<Package>) clientDao.findAll();
}

}

【问题讨论】:

    标签: spring spring-boot spring-mvc spring-data-jpa


    【解决方案1】:

    谢谢大家,我解决了这个问题。 实体“Package”名称中的问题,它在Java中保留?

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 2019-02-22
      • 2021-07-23
      • 2020-11-25
      • 2017-05-15
      • 2018-03-19
      • 2021-06-23
      • 2019-08-08
      • 2020-12-12
      相关资源
      最近更新 更多