【问题标题】:Inject controller in Vaadin view Spring Boot在 Vaadin 视图 Spring Boot 中注入控制器
【发布时间】:2015-12-29 09:55:21
【问题描述】:

我使用 Spring Boot 和 Vaadin 为应用程序接口开发应用程序 Web。

我的问题是无法inyect控制器查看,应用程序启动正常,但是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);

LoginView 中,bean ViewController 为空。

如何在视图中插入bean

谢谢。

【问题讨论】:

    标签: spring-boot vaadin7 vaadin4spring


    【解决方案1】:

    您无法访问构造函数中的自动装配字段,因为此时尚未完成注入。添加一个带有@PostConstruct注解的方法,将在注入字段后执行:

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

    这不是 vaadin4spring 特有的,这就是 Spring 的工作原理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-18
      • 1970-01-01
      • 2014-11-06
      • 2017-06-05
      • 2016-10-19
      • 2017-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多