java - Spring - 自动连接依赖项的注入失败

时间:2017-04-05 14:41:42

标签: java spring hibernate spring-mvc

- 我正在尝试创建映射购物车实体。但显示与Injection of autowired dependencies failed相关的404错误 检查我的来源并帮我解决它..

映射计划:

客户-----一对一------>购物车-------- onetomany --->产品

客户

package com.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;


@Entity
public class Customer {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="Cid") 
private int customerId;
@Column(name="password")
@NotEmpty(message="Name is mandatory")
private String password;
@Column(name="Email") 
@NotEmpty(message="Name is mandatory")
private String email;
@NotEmpty(message="First Name is mandatory")
@Column(name="firstname")
private String firstName;
@NotEmpty(message="Last Name is mandatory")
@Column(name="lastname")
private String lastName;
@Column(name="Mobile")
@Size(min = 10)
@NotEmpty(message="Mobile is mandatory")
private String mobile;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="address_id")
private Address delAdderss;
private boolean enabled;
private String role;
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="cart_id")
private Cart cart;
public int getCustomerId() {
    return customerId;
}
public void setCustomerId(int customerId) {
    this.customerId = customerId;
}
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}
public String getEmail() {
    return email;
}
public void setEmail(String email) {
    this.email = email;
}
public String getFirstName() {
    return firstName;
}
public void setFirstName(String firstName) {
    this.firstName = firstName;
}
public String getLastName() {
    return lastName;
}
public void setLastName(String lastName) {
    this.lastName = lastName;
}
public String getMobile() {
    return mobile;
}
public void setMobile(String mobile) {
    this.mobile = mobile;
}
public Address getDelAdderss() {
    return delAdderss;
}
public void setDelAdderss(Address delAdderss) {
    this.delAdderss = delAdderss;
}
public boolean isEnabled() {
    return enabled;
}
public void setEnabled(boolean enabled) {
    this.enabled = enabled;
}
public String getRole() {
    return role;
}
public void setRole(String role) {
    this.role = role;
}
public Cart getCart() {
    return cart;
}
public void setCart(Cart cart) {
    this.cart = cart;
}

}

package com.model;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;


@Entity
public class Cart {
@Id 
@GeneratedValue(strategy=GenerationType.AUTO)
private int cart_id;
@Column
private double total;
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="CID")
private Customer customer;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name="id")
private List<Product> product;
public int getCart_id() {
return cart_id;
}
public void setCart_id(int cart_id) {
this.cart_id = cart_id;
}

public double getTotal() {
return total;
}


public void setTotal(double total) {
this.total = total;
}

public List<Product> getProduct() {
return product;
}


public void setProduct(List<Product> product) {
this.product = product;
}

}

产品

package com.model;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import org.springframework.web.multipart.MultipartFile;

@Entity
public class Product {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@Column
private String product_Name;
@Column
private String descripction;
@Column
private int price;
@Column
private Date mfg_Date;
@Transient
private MultipartFile image;

@ManyToOne(cascade = CascadeType.ALL)

private List<Cart> cart;

public int getId() {
    return id;
}

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

public String getProduct_Name() {
    return product_Name;
}

public void setProduct_Name(String product_Name) {
    this.product_Name = product_Name;
}

public String getDescripction() {
    return descripction;
}

public void setDescripction(String descripction) {
    this.descripction = descripction;
}

public int getPrice() {
    return price;
}

public void setPrice(int price) {
    this.price = price;
}

public Date getMfg_Date() {
    return mfg_Date;
}

public void setMfg_Date(Date mfg_Date) {
    this.mfg_Date = mfg_Date;
}

public MultipartFile getImage() {
    return image;
}

public void setImage(MultipartFile image) {
    this.image = image;
}

public List<Cart> getCarts() {
    return cart;
}

public void setCarts(List<Cart> carts) {
    this.cart= carts;
}

}

0 个答案:

没有答案
相关问题