2015-12-29 74 views
0

我使用Spring Boot和Vaadin爲應用程序界面開發應用程序Web。Vaadin視圖中的注入控制器Spring Boot

我的問題是不能監視控制器查看,應用程序啓動正常,但該bean在執行中爲空。

我的控制器:

@Component 
public class ViewController { 

/** Inyección de Spring para poder acceder a la capa de datos.*/ 
@Autowired 
private CommonSetup commonSetup; 

/** 
* This method gets the user from db. 
*/ 
public Temployee getUser(String username, String password) { 
    Temployee empl = null; 
    // get from db the user 
    empl = commonSetup.getUserByUsernameAndPass(username, password); 

    // return the employee found. 
    return empl; 
} 

... ...

我的觀點:

@Theme("login") 
@SpringUI 
public class LoginView extends CustomComponent implements View ,Button.ClickListener { 

/** The view controller. */ 
@Autowired 
private ViewController vContr; 

public LoginView() { 
    setSizeFull(); 

    ... 
    ... 

    // Check if the username and the password are correct. 
    Temployee empleado = vContr.getUser(username, password); 

LoginViewbean ViewController爲空。

如何在視圖中檢查bean

謝謝。

回答

0

您無法在構造函數中訪問自動佈線的字段,因爲此時尚未完成注入。添加方法與@PostConstruct註釋字段注入後,將被執行:

@PostConstruct 
public void init() { 
    // Check if the username and the password are correct. 
    Temployee empleado = vContr.getUser(username, password); 
} 

這沒什麼具體到vaadin4spring,這是春季如何工作的。

相關問題