You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Igor Vaynberg <ig...@gmail.com> on 2009/06/01 00:03:16 UTC
Re: Spring Autowired and @SpringBean
wicket is looking for these beans in the spring context. if spring is
not putting those beans there then it will be a problem.
-igor
On Sun, May 31, 2009 at 2:19 PM, Luther Baker <lu...@gmail.com> wrote:
> I'm using the following from the wicket spring page:
>
>
> public class MainApplication extends WebApplication
> {
> /**
> * @see org.apache.wicket.protocol.http.WebApplication#init()
> */
> @Override
> protected void init()
> {
> super.init();
>
> // http://cwiki.apache.org/WICKET/spring.html
> final SpringComponentInjector spring = new
> SpringComponentInjector(this);
> addComponentInstantiationListener(spring);
> }
>
>
> and spring indeed is wiring up the daos and services. The @Service beans are
> correctly receieving their @Respository dependencies. It is just the wicket
> page '@SpringBean' annotation don't seem to be able to fine the beans
> annotated with @Service.
>
> Is it possible that @Autowire doesn't work with @SpringBean and that I need
> to explicitly list dependencies in a config file?
>
> -Luther
>
>
>
>
> On Sun, May 31, 2009 at 3:55 PM, Igor Vaynberg <ig...@gmail.com>wrote:
>
>> have you read the wicket spring wiki page? you have to install the
>> spring component injector for this to work.
>>
>> -igor
>>
>> On Sun, May 31, 2009 at 1:15 PM, Luther Baker <lu...@gmail.com>
>> wrote:
>> > I'm working on a project with Spring/Wicket integration.
>> >
>> > I have most of the Spring autowire stuff working ...
>> >
>> > My @Repository(s) are successfully autowires to my @Service(s). In
>> SpringMVC
>> > speak then, the @Service would autowire to the *@Controller*. But of
>> course,
>> > I am using wicket, not Spring MVC. Per the wicket/spring doc
>> > page<http://cwiki.apache.org/WICKET/spring.html>,
>> > which describes the *@SpringBean* annotation, as opposed to the
>> *@Controller
>> > * annotation, in my pages. Unfortunately, I get an error and the stack
>> trace
>> > includes:
>> >
>> > Caused by: java.lang.IllegalStateException: bean of type
>> > [org.effectiveprogramming.effprog.service.PostService] not found
>> >
>> > Is this expected? Before deep diving I'm curious to confirm that
>> > spring-wicket integration is definitely supposed to work with Spring
>> > autowiring. Thoughts?
>> >
>> > Thanks.
>> >
>> > -Luther
>> >
>> >
>> > --------
>> >
>> > @Repository
>> > public class PostDaoImpl extends PostDao
>> > {
>> > ...
>> > }
>> >
>> > --------
>> >
>> > @Service
>> > public class PostServiceImpl implements PostService
>> > {
>> > ...
>> > @Autowired
>> > public void setPostDao(final PostDao postDao)
>> > {
>> > this.postDao = postDao;
>> > }
>> > }
>> >
>> > --------
>> >
>> > public class HomePage extends BasicLayout
>> > {
>> > @SpringBean
>> > private PostService postService;
>> >
>>
>> ---------------------------------------------------------------------
>> 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: Spring Autowired and @SpringBean
Posted by Luther Baker <lu...@gmail.com>.
Thanks Jeoren.
I wasn't using @Component - that could very well be it.
I'll try it - and thanks for suggestion.
-Luther
On Tue, Jun 2, 2009 at 2:42 PM, Jeroen Steenbeeke <j.steenbeeke.ml@gmail.com
> wrote:
> Not sure if this will help, but I have the following in my Spring
> configuration file:
> <?xml version="1.0" encoding="utf-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:context="http://www.springframework.org/schema/context"
> xsi:schemaLocation="http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
> http://www.springframework.org/schema/context
> http://www.springframework.org/schema/context/spring-context-2.5.xsd
> ">
> <context:annotation-config />
>
> <context:component-scan
> base-package="path.to.my.beans.impl" />
> </beans>
> For each bean implementation I use
> @org.springframework.stereotype.Component, and for each property that needs
> to be set on these beans I use
> @org.springframework.beans.factory.annotation.Autowired.
> This way you can do the following:
>
> @Component
> public class FooServiceImpl implements FooService {
> @Autowired
> private BarService bar;
> public void doSomething() {
> // Does something
> }
> public void setBar(BarService bar) {
> this.bar = bar;
> }
> }
> And in your Wicket pages you use:
> public class MyPage extends Page {
> @SpringBean
> private FooService service;
> public MyPage() {
> super();
> service.doSomething();
> }
> }
> And of course, don't forget the SpringComponentInjector (which you already
> have) - and the required fields in your web.xml:
>
> <context-param>
> <param-name>contextConfigLocation</param-name>
> <param-value>classpath:your_application_context.xml</param-value>
> </context-param>
> Hope this helps,
> Jeroen
>
Re: Spring Autowired and @SpringBean
Posted by Jeroen Steenbeeke <j....@gmail.com>.
Not sure if this will help, but I have the following in my Spring
configuration file:
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
">
<context:annotation-config />
<context:component-scan
base-package="path.to.my.beans.impl" />
</beans>
For each bean implementation I use
@org.springframework.stereotype.Component, and for each property that needs
to be set on these beans I use
@org.springframework.beans.factory.annotation.Autowired.
This way you can do the following:
@Component
public class FooServiceImpl implements FooService {
@Autowired
private BarService bar;
public void doSomething() {
// Does something
}
public void setBar(BarService bar) {
this.bar = bar;
}
}
And in your Wicket pages you use:
public class MyPage extends Page {
@SpringBean
private FooService service;
public MyPage() {
super();
service.doSomething();
}
}
And of course, don't forget the SpringComponentInjector (which you already
have) - and the required fields in your web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:your_application_context.xml</param-value>
</context-param>
Hope this helps,
Jeroen
Re: Spring Autowired and @SpringBean
Posted by Luther Baker <lu...@gmail.com>.
Thanks for the suggestion Vasu. I tried this in my 'Service' class:
@Service(value = "logServiceImpl")
public class LogServiceImpl implements LogService
{
...
and this in my page:
public class Home extends BasicLayout
{
@SpringBean(name = "logServiceImpl")
private LogService logService;
...
as well as
public class Home extends BasicLayout
{
@SpringBean
private LogService logService;
I even changed the type in the destination classes to LogServiceImpl and no
luck.
I'm afraid the @Autowire stuff in Spring doesn't work seem to work with
@SpringBean.
Again, thanks for the suggestion. I'm thinking to go back to Guice and
manage transactions without Spring.
-Luther
Depending on what I'm testing, errors look like:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
bean named 'logServiceImpl' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:387)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:971)
at org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(AbstractBeanFactory.java:358)
at org.springframework.context.support.AbstractApplicationContext.isSingleton(AbstractApplicationContext.java:896)
at org.apache.wicket.spring.SpringBeanLocator.isSingletonBean(SpringBeanLocator.java:135)
at org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(AnnotProxyFieldValueFactory.java:92)
at org.apache.wicket.injection.Injector.inject(Injector.java:108)
or
java.lang.IllegalStateException: bean of type
[com.fuzzybearings.fuzzy.service.LogService] not found
at org.apache.wicket.spring.SpringBeanLocator.getBeanNameOfClass(SpringBeanLocator.java:109)
at org.apache.wicket.spring.SpringBeanLocator.getBeanName(SpringBeanLocator.java:195)
at org.apache.wicket.spring.SpringBeanLocator.isSingletonBean(SpringBeanLocator.java:135)
at org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(AnnotProxyFieldValueFactory.java:92)
at org.apache.wicket.injection.Injector.inject(Injector.java:108)
or
java.lang.IllegalStateException: bean of type
[com.fuzzybearings.fuzzy.service.LogServiceImpl] not found
at org.apache.wicket.spring.SpringBeanLocator.getBeanNameOfClass(SpringBeanLocator.java:109)
at org.apache.wicket.spring.SpringBeanLocator.getBeanName(SpringBeanLocator.java:195)
at org.apache.wicket.spring.SpringBeanLocator.isSingletonBean(SpringBeanLocator.java:135)
at org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(AnnotProxyFieldValueFactory.java:92)
at org.apache.wicket.injection.Injector.inject(Injector.java:108)
On Sun, May 31, 2009 at 10:47 PM, Vasu Srinivasan <va...@gmail.com> wrote:
> Have you tried like this:
> @SpringBean(name = "xServiceImpl") XService xservice;
>
>
>
> On Sun, May 31, 2009 at 5:03 PM, Igor Vaynberg <igor.vaynberg@gmail.com
> >wrote:
>
> > wicket is looking for these beans in the spring context. if spring is
> > not putting those beans there then it will be a problem.
> >
> > -igor
> >
> > On Sun, May 31, 2009 at 2:19 PM, Luther Baker <lu...@gmail.com>
> > wrote:
> > > I'm using the following from the wicket spring page:
> > >
> > >
> > > public class MainApplication extends WebApplication
> > > {
> > > /**
> > > * @see org.apache.wicket.protocol.http.WebApplication#init()
> > > */
> > > @Override
> > > protected void init()
> > > {
> > > super.init();
> > >
> > > // http://cwiki.apache.org/WICKET/spring.html
> > > final SpringComponentInjector spring = new
> > > SpringComponentInjector(this);
> > > addComponentInstantiationListener(spring);
> > > }
> > >
> > >
> > > and spring indeed is wiring up the daos and services. The @Service
> beans
> > are
> > > correctly receieving their @Respository dependencies. It is just the
> > wicket
> > > page '@SpringBean' annotation don't seem to be able to fine the beans
> > > annotated with @Service.
> > >
> > > Is it possible that @Autowire doesn't work with @SpringBean and that I
> > need
> > > to explicitly list dependencies in a config file?
> > >
> > > -Luther
> > >
> > >
> > >
> > >
> > > On Sun, May 31, 2009 at 3:55 PM, Igor Vaynberg <
> igor.vaynberg@gmail.com
> > >wrote:
> > >
> > >> have you read the wicket spring wiki page? you have to install the
> > >> spring component injector for this to work.
> > >>
> > >> -igor
> > >>
> > >> On Sun, May 31, 2009 at 1:15 PM, Luther Baker <lu...@gmail.com>
> > >> wrote:
> > >> > I'm working on a project with Spring/Wicket integration.
> > >> >
> > >> > I have most of the Spring autowire stuff working ...
> > >> >
> > >> > My @Repository(s) are successfully autowires to my @Service(s). In
> > >> SpringMVC
> > >> > speak then, the @Service would autowire to the *@Controller*. But of
> > >> course,
> > >> > I am using wicket, not Spring MVC. Per the wicket/spring doc
> > >> > page<http://cwiki.apache.org/WICKET/spring.html>,
> > >> > which describes the *@SpringBean* annotation, as opposed to the
> > >> *@Controller
> > >> > * annotation, in my pages. Unfortunately, I get an error and the
> stack
> > >> trace
> > >> > includes:
> > >> >
> > >> > Caused by: java.lang.IllegalStateException: bean of type
> > >> > [org.effectiveprogramming.effprog.service.PostService] not found
> > >> >
> > >> > Is this expected? Before deep diving I'm curious to confirm that
> > >> > spring-wicket integration is definitely supposed to work with Spring
> > >> > autowiring. Thoughts?
> > >> >
> > >> > Thanks.
> > >> >
> > >> > -Luther
> > >> >
> > >> >
> > >> > --------
> > >> >
> > >> > @Repository
> > >> > public class PostDaoImpl extends PostDao
> > >> > {
> > >> > ...
> > >> > }
> > >> >
> > >> > --------
> > >> >
> > >> > @Service
> > >> > public class PostServiceImpl implements PostService
> > >> > {
> > >> > ...
> > >> > @Autowired
> > >> > public void setPostDao(final PostDao postDao)
> > >> > {
> > >> > this.postDao = postDao;
> > >> > }
> > >> > }
> > >> >
> > >> > --------
> > >> >
> > >> > public class HomePage extends BasicLayout
> > >> > {
> > >> > @SpringBean
> > >> > private PostService postService;
> > >> >
> > >>
> > >> ---------------------------------------------------------------------
> > >> 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
> >
> >
>
>
> --
> Regards,
> Vasu Srinivasan
>
Re: Spring Autowired and @SpringBean
Posted by Vasu Srinivasan <va...@gmail.com>.
Have you tried like this:
@SpringBean(name = "xServiceImpl") XService xservice;
On Sun, May 31, 2009 at 5:03 PM, Igor Vaynberg <ig...@gmail.com>wrote:
> wicket is looking for these beans in the spring context. if spring is
> not putting those beans there then it will be a problem.
>
> -igor
>
> On Sun, May 31, 2009 at 2:19 PM, Luther Baker <lu...@gmail.com>
> wrote:
> > I'm using the following from the wicket spring page:
> >
> >
> > public class MainApplication extends WebApplication
> > {
> > /**
> > * @see org.apache.wicket.protocol.http.WebApplication#init()
> > */
> > @Override
> > protected void init()
> > {
> > super.init();
> >
> > // http://cwiki.apache.org/WICKET/spring.html
> > final SpringComponentInjector spring = new
> > SpringComponentInjector(this);
> > addComponentInstantiationListener(spring);
> > }
> >
> >
> > and spring indeed is wiring up the daos and services. The @Service beans
> are
> > correctly receieving their @Respository dependencies. It is just the
> wicket
> > page '@SpringBean' annotation don't seem to be able to fine the beans
> > annotated with @Service.
> >
> > Is it possible that @Autowire doesn't work with @SpringBean and that I
> need
> > to explicitly list dependencies in a config file?
> >
> > -Luther
> >
> >
> >
> >
> > On Sun, May 31, 2009 at 3:55 PM, Igor Vaynberg <igor.vaynberg@gmail.com
> >wrote:
> >
> >> have you read the wicket spring wiki page? you have to install the
> >> spring component injector for this to work.
> >>
> >> -igor
> >>
> >> On Sun, May 31, 2009 at 1:15 PM, Luther Baker <lu...@gmail.com>
> >> wrote:
> >> > I'm working on a project with Spring/Wicket integration.
> >> >
> >> > I have most of the Spring autowire stuff working ...
> >> >
> >> > My @Repository(s) are successfully autowires to my @Service(s). In
> >> SpringMVC
> >> > speak then, the @Service would autowire to the *@Controller*. But of
> >> course,
> >> > I am using wicket, not Spring MVC. Per the wicket/spring doc
> >> > page<http://cwiki.apache.org/WICKET/spring.html>,
> >> > which describes the *@SpringBean* annotation, as opposed to the
> >> *@Controller
> >> > * annotation, in my pages. Unfortunately, I get an error and the stack
> >> trace
> >> > includes:
> >> >
> >> > Caused by: java.lang.IllegalStateException: bean of type
> >> > [org.effectiveprogramming.effprog.service.PostService] not found
> >> >
> >> > Is this expected? Before deep diving I'm curious to confirm that
> >> > spring-wicket integration is definitely supposed to work with Spring
> >> > autowiring. Thoughts?
> >> >
> >> > Thanks.
> >> >
> >> > -Luther
> >> >
> >> >
> >> > --------
> >> >
> >> > @Repository
> >> > public class PostDaoImpl extends PostDao
> >> > {
> >> > ...
> >> > }
> >> >
> >> > --------
> >> >
> >> > @Service
> >> > public class PostServiceImpl implements PostService
> >> > {
> >> > ...
> >> > @Autowired
> >> > public void setPostDao(final PostDao postDao)
> >> > {
> >> > this.postDao = postDao;
> >> > }
> >> > }
> >> >
> >> > --------
> >> >
> >> > public class HomePage extends BasicLayout
> >> > {
> >> > @SpringBean
> >> > private PostService postService;
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> 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
>
>
--
Regards,
Vasu Srinivasan