2016-11-28 5 views
1

프로젝트를 다음과 같이 생성했습니다 : 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가 작동하지 않습니다. 내 실수는 어디인지 모르겠다. ...

답변

0

잘 @SpringBootApplication 동일한 패키지 및 아래에있는 구성 요소 만 검색합니다. 그 이유는 응용 프로그램이 @Autowire를 만들 수 없기 때문입니다. 예를 들어, 모든 클래스는 다른 패키지에 있습니다.

Application 클래스를 최상위 패키지에 넣으면 수정이 가능하고 @ComponentScan은 수동으로 정의하여 특정 패키지를 검사 할 수 있습니다.