Получение сообщений об ошибках, и я устранил все, что мог, но это не сработает. Я получаю сообщение об ошибке, что может быть не так?
Вот контроллер:
package com.Controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.Model.*;
import com.Service.UserAccountService;
@RestController
public class UserController {
@Autowired
UserAccountService userService;
@RequestMapping(path = "/users/")
public List<UserAccount> getUsers()
{
return userService.getUsers();
}
}
Это интерфейс службы и ServiceImpl:
package com.Service;
import java.util.List;
import com.Exceptions.UserNotFoundException;
import com.Model.UserAccount;
public interface UserAccountService {
UserAccount save(UserAccount user) throws Exception;
List<UserAccount> getUsers();
UserAccount update(UserAccount user, int id) throws Exception;
//UserAccount delete(UserAccount user) throws Exception;
UserAccount userAccountByKey(int id) throws UserNotFoundException;
}
Это код реализации службы:
package com.ServiceImpl;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.Exceptions.UserNotFoundException;
import com.Model.UserAccount;
import com.Repository.UserRepo;
import com.Service.UserAccountService;
@Service
public class UserAccountServiceImplementation implements UserAccountService {
@Autowired
private UserRepo repo;
@Override
public List<UserAccount> getUsers() {
// TODO Auto-generated method stub
List<UserAccount> users = new ArrayList<>();
repo.findAll().forEach(users::add);
return users;
}
Это код модели:
package com.Model;
import java.util.Date;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
//import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
@Entity
public class UserAccount {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@NotNull
private String userName;
private String email;
@Temporal(TemporalType.DATE)
private Date dateCreated;
@OneToMany(mappedBy = "userAccount", fetch = FetchType.EAGER)
private Set <Transaction> transactions = new HashSet<>();
public UserAccount(int id) {
super();
this.id = id;
}
public UserAccount(String userName, String email, Date dateCreated) {
super();
this.userName = userName;
this.email = email;
this.dateCreated = dateCreated;
}
public UserAccount(int id, String userName, String email, Date dateCreated) {
super();
this.id = id;
this.userName = userName;
this.email = email;
this.dateCreated = dateCreated;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getDateCreated() {
return dateCreated;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
public Set<Transaction> getTransactions() {
return transactions;
}
public void setTransactions(Set<Transaction> transactions) {
this.transactions = transactions;
}
@Override
public int hashCode() {
return Objects.hash(id,userName,email,dateCreated);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
UserAccount other = (UserAccount) obj;
if (!Objects.equals(this.id, other.id)) {
return false;
}
return true;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder ("UserAccount{");
sb.append("id=").append(id);
sb.append(",username='").append(userName).append('\'');
sb.append(",email='").append(email).append('\'');
sb.append(",date='").append(dateCreated).append('\'');
sb.append('}');
return sb.toString();
}
}
Это мои данные application.properties:
spring.h2.console.enabled=true
spring.datasource.platform=h2
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:mojec
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.datasource.data=classpath:data.sql
Это беспокоит меня.