프로젝트를 다음과 같이 생성했습니다 : http://start.spring.io/ maven으로 빌드하고 실행 중입니다.스프링 부트 Vaadin7 통합 - @Autowired와 바인딩 할 수 없습니다.
그래서 내가 만드는거야 엔티티 담당자 :
@Entity
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Temporal(TemporalType.TIMESTAMP)
private Date birthDay;
@NotNull(message = "Name is required")
@Size(min = 3, max = 50, message = "Name must be longer than 3 and less than 40 characters")
private String name;
private Boolean colleague;
private String phoneNumber;
@NotNull(message = "Email is required")
@Pattern(regexp = "[email protected]+\\.[a-z]+", message = "Must be valid email")
private String email;
//----- GETTERS AND SETTERS -----------
}
이 엔티티 임 만드는 저장소 PersonRepo의 경우 : 여기에만
@SpringUI
@Theme("valo")
public class MyUI extends UI {
private static final long serialVersionUID = 1L;
private final PersonRepo personRepo;
@Autowired
private MyUI(PersonRepo personRepo) {
this.personRepo = personRepo;
}
@Override
protected void init(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout();
layout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
Person person = new Person();
person.setName("Person");
person.setEmail("Email");
person.setColleague(false);
person.setBirthDay(new Date());
personRepo.save(person);
Label helloWorld = new Label();
helloWorld.setValue("Persons: " + personRepo.count());
helloWorld.setStyleName(ValoTheme.LABEL_H1);
helloWorld.setSizeUndefined();
layout.addComponent(helloWorld);
setContent(layout);
}
}
@ : 여기
public interface PersonRepo extends JpaRepository<Person, Long> {
@Override
<S extends Person> S save(S arg0);
@Override
long count();
}
는 myUI 클래스 PersonRepo를 Autowire하고, Label에서보다 Person을 생성하고 db로 저장합니다. Person 수를 보여줍니다. 하지만 personRepo가 null이고 @Autowire가 작동하지 않습니다. 내 실수는 어디인지 모르겠다. ...