0

Spring boot. Injection SpringBean into viewModel.

asked 2019-10-21 22:07:07 +0800

Evgenic gravatar image Evgenic
14 3

Hello,

zkVersion = 8.6.2; zkspringboot-starter, version: '1.0.4;

I am trying to inject SpringBean into my viewModel:

zul:

<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<zk xmlns="http://www.zkoss.org/2005/zul">
     <div
     apply="org.zkoss.bind.BindComposer"
     viewModel="@id('vm')
     @init('ru.apertum.qsystem.prereg.ClientForm')"...

viewModel:

@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class)
public class ClientForm extends Index {

    @WireVariable
    private AppConfig myConfig;
...
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
    myConfig == null!!!  <<--- always NULL
}

... }

AppConfig :

@Configuration
@PropertySource(value = "file:props.properties", name = "prp", encoding = "utf8")
@Scope(proxyMode= ScopedProxyMode.TARGET_CLASS)
public class AppConfig {...}

Mostly it is all. But field 'myConfig' is NULL always. What did I wrong?

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-10-22 12:27:21 +0800

cor3000 gravatar image cor3000
4887 2 7
ZK Team

updated 2019-10-22 12:28:01 +0800

ZK's @WireVariable-annotation specifies a VariableResolver, which is wiring by name.

What's missing is, giving your configuration a matching bean id/name:

@Configuration("myConfig")

so that it matches your annotated variable.

@WireVariable
private AppConfig myConfig;

Or you can rename your variable to match the automatic bean id assigned by spring.

@WireVariable
private AppConfig appConfig;

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/AnnotationBeanNameGenerator.html

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2019-10-21 22:07:07 +0800

Seen: 9 times

Last updated: Oct 22

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