Revision history [back]

click to hide/show revision 1
initial version

asked 2017-02-13 12:42:46 +0800

Coderdood gravatar image Coderdood

Spring and Constructor Injection

Hello,

So far, I've been using @WireVariable to inject Spring beans on my controllers and it's known to work perfectly.

@WireVariable("someBean") 
private SomeBean someBean;

But here is my question... Is there a way to achieve the same result but with constructor injection? It's a known good practice to inject beans via constructor so it's easy to mock them on unit tests and such. Like this

private final SomeBean somebean;

public MyController(SomeBean someBean) {
    this.somebean = someBean
}

Can this be achieved somehow or I simply cannot unit test a ZK Controller?

Spring and Constructor Injection

Hello,

So far, I've been using @WireVariable to inject Spring beans on my controllers and it's known to work perfectly.

@WireVariable("someBean") 
private SomeBean someBean;

But here is my question... Is there a way to achieve the same result but with constructor injection? It's a known good practice to inject beans via constructor so it's easy to mock them on unit tests and such. Like this

private final SomeBean somebean;

public MyController(SomeBean someBean) {
    this.somebean = someBean
someBean;
}

Can this be achieved somehow or I simply cannot unit test a ZK Controller?

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More