我已经添加了@ XiamentScan,@ XiamtyScan在主类仍然是相同的错误,我是新来的,从几天得到这个错误.请帮助解决这个问题.
StackTrace:
第一个月
主类
@SpringBootApplication
//@ComponentScan(basePackages = {"org.simplilearn"})
//@EntityScan(basePackages = "org.simplilearn")
public class MedicareApplication {
public static void main(String[] args) {
SpringApplication.run(MedicareApplication.class, args);
}
}
字符串
用户服务
@Service
public class UserService {
@Autowired
private UserRepository userRepo;
// Save the User to the database(POST METHOD)
public User saveUser(User user)
{
return userRepo.save(user);
}
//Fetch the User from Database(GET METHOD)
public List<User> getUsers(){
return userRepo.findAll();
}
public User getUserById(int id) {
return userRepo.findById(id).orElse(null);
}
//Delete the User from Database (DELETE METHOD)
public String deleteUserById(int id) {
userRepo.deleteById(id);
return "Data" +id+ "Deleted Successfully!";
}
//Join the User and Product Table
public List<OrderResponse> getUserProductJoinInfos(){
return userRepo.joinUserProductTable();
}
}
型
UserRepository
@Repository
public interface UserRepository extends JpaRepository<User, Integer> {
@Query("SELECT new org.simplilearn.entity.OrderResponse(u.UserId,u.name,u.email, u.mobile, u.address, p.medicinename, p.seller"+ ", p.price, p.description, p.quantity, p.orderDateTime) FROM User u JOIN u.products p")
public List<OrderResponse> joinUserProductTable();
}
型
用户实体
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int UserId;
private int age;
private String name;
private String email;
private String gender;
private String address;
private String mobile;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "USER_PRODUCT_TABLE", joinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "UserId") }, inverseJoinColumns = { @JoinColumn(name = "product_id", referencedColumnName = "pid") })
private List<Product> products;
public User() {
}
public User( int age, String name, String email, String gender, String address, String mobile, List<Product> products) {
super();
this.age = age;
this.name = name;
this.email = email;
this.gender = gender;
this.address = address;
this.mobile = mobile;
this.products = products;
}
public int getUserId() {
return UserId;
}
public void setUserId(int userId) {
UserId = userId;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
@Override
public String toString() {
return "User [UserId=" + UserId + ", age=" + age + ", name=" + name + ", email=" + email + ", gender=" + gender
+ ", address=" + address + ", mobile=" + mobile + ", products=" + products + "]";
}
}
型
我已经添加了@ XiamentScan,@ XiamtyScan在主类仍然是相同的错误,我是新来的,从几天得到这个错误.请帮助解决这个问题.
1条答案
按热度按时间ui7jx7zq1#
@SpringBootApplication里面已经有**@ WebentScan了,你可以将鼠标悬停在annotation上,看到列表,它会扫描Java下的com.example.myApplication**文件夹,如果你的组件不在这里,它就无法扫描。
如果你有任何错别字,我也会检查查询中的列名。