You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by dan123 <ci...@email.cz> on 2013/09/26 21:08:12 UTC

wicket + autowired annotation

Hi,
I have simple project created from Quickstart, and I have deffined in
springContext.xml bean named "dbAccess".
When I use: *@SpringBean private DbAccess dbAccess;* in *class HomePage
extends WebPage*.
It works, it creates bean and in constructor "HomePage" class I can access
to dbAccess.

But when I create class with one method:
public class ClsDb {
@Autowired private DbAccess dbAccess;
public void save() {
 // ... dbAccess.... save something
}
}

and in HomePage class I use "new ClsDb().save();", "dbAccess" in ClsDb is
null.

What is neccessary to do for use @Autowired in ClsDb class?
Thanks.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-autowired-annotation-tp4661529.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: wicket + autowired annotation

Posted by miguel <mi...@thedeanda.com>.
If you are using _only_ spring and no wicket you _still_ can't do the "new
ClsDb()" method and have the @Autowired fields populated. You're question
isn't really specific to wicket anymore in that situation.


On Fri, Sep 27, 2013 at 12:32 PM, dan123 [via Apache Wicket] <
ml-node+s1842946n4661583h64@n4.nabble.com> wrote:

> Thanks to everybody for help.
>
> Paul Bors wrote
> As far as I can tell you the Spring native annotations work within the
> implementation of a bean you already injected in your wicket component.
> First crate a service for yourself and inject it where needed in Wicket
> via
> @SpringBean. Then inside your service feel free to inject other Spring
> dependencies via Spring's native annotations.
>
>
> It works.
> But I thought, that I can set something (something like a scanning all
> classes) in web.xml or springContext.xml file to scan for all @Autowired
> annotations and it will be autowired in all classes. So why I have to use
> "@SpringBean ClsDb clsDb;" in my HomePage.class and then I can use
> @Autowired in CldDb class. Why I cannon use only "new ClsDb();"? There is
> no way how to autowired all beans?
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-wicket.1842946.n4.nabble.com/wicket-autowired-annotation-tp4661529p4661583.html
>  To unsubscribe from wicket + autowired annotation, click here<http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4661529&code=bWlndWVsQHRoZWRlYW5kYS5jb218NDY2MTUyOXwxNjAzMjU4NTI=>
> .
> NAML<http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-autowired-annotation-tp4661529p4661586.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: wicket + autowired annotation

Posted by dan123 <ci...@email.cz>.
Thanks to everybody for help.


Paul Bors wrote
> As far as I can tell you the Spring native annotations work within the
> implementation of a bean you already injected in your wicket component.
> First crate a service for yourself and inject it where needed in Wicket
> via
> @SpringBean. Then inside your service feel free to inject other Spring
> dependencies via Spring's native annotations.


It works.
But I thought, that I can set something (something like a scanning all
classes) in web.xml or springContext.xml file to scan for all @Autowired
annotations and it will be autowired in all classes. So why I have to use
"@SpringBean ClsDb clsDb;" in my HomePage.class and then I can use
@Autowired in CldDb class. Why I cannon use only "new ClsDb();"? There is no
way how to autowired all beans?



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-autowired-annotation-tp4661529p4661583.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: wicket + autowired annotation

Posted by Kristian Rosenvold <kr...@gmail.com>.
You cannot use "new" to create a spring bean in you HomePage class.
You must use @SpringBean on "ClsDb"

Kristian


2013/9/26 dan123 <ci...@email.cz>:
> Hi,
> I have simple project created from Quickstart, and I have deffined in
> springContext.xml bean named "dbAccess".
> When I use: *@SpringBean private DbAccess dbAccess;* in *class HomePage
> extends WebPage*.
> It works, it creates bean and in constructor "HomePage" class I can access
> to dbAccess.
>
> But when I create class with one method:
> public class ClsDb {
> @Autowired private DbAccess dbAccess;
> public void save() {
>  // ... dbAccess.... save something
> }
> }
>
> and in HomePage class I use "new ClsDb().save();", "dbAccess" in ClsDb is
> null.
>
> What is neccessary to do for use @Autowired in ClsDb class?
> Thanks.
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-autowired-annotation-tp4661529.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: wicket + autowired annotation

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

On Fri, Sep 27, 2013 at 8:41 AM, miguel <mi...@thedeanda.com> wrote:

> how do you instantiate ClsDb? I don't see a @Component/@Service/etc
> annotation on it so my guess is you use something like...
>
> clsdb = new ClsDb();
> clsdb.save();
>
> You need to have the class creaed by spring's bean factory or injected by
> wicket's component instantiation listener.
>

If you create it with "new ClsDb" then you can do:

public ClsDb() {
    ....
    Injector.get().inject(this);
}


>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/wicket-autowired-annotation-tp4661529p4661543.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

RE: wicket + autowired annotation

Posted by Paul Bors <pa...@bors.ws>.
Read section 17.2 "Integrating Wicket with Spring" starting on page 176 of
the Free Wicket Guide:
http://wicket.apache.org/learn/books/freeguide.html

As far as I can tell you the Spring native annotations work within the
implementation of a bean you already injected in your wicket component.
First crate a service for yourself and inject it where needed in Wicket via
@SpringBean. Then inside your service feel free to inject other Spring
dependencies via Spring's native annotations.

~ Thank you,
  Paul Bors

-----Original Message-----
From: miguel [mailto:miguel@thedeanda.com] 
Sent: Friday, September 27, 2013 12:41 PM
To: users@wicket.apache.org
Subject: Re: wicket + autowired annotation

I forgot to also mention...

I've noticed that @Autowired does NOT work whereas @Inject does. Also,
@Value annotations don't work either.



--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/wicket-autowired-annotation-tp466
1529p4661575.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: wicket + autowired annotation

Posted by miguel <mi...@thedeanda.com>.
I forgot to also mention...

I've noticed that @Autowired does NOT work whereas @Inject does. Also,
@Value annotations don't work either.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-autowired-annotation-tp4661529p4661575.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: wicket + autowired annotation

Posted by miguel <mi...@thedeanda.com>.
how do you instantiate ClsDb? I don't see a @Component/@Service/etc
annotation on it so my guess is you use something like...

clsdb = new ClsDb();
clsdb.save();

You need to have the class creaed by spring's bean factory or injected by
wicket's component instantiation listener.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-autowired-annotation-tp4661529p4661543.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org