You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Otho <ta...@googlemail.com> on 2009/06/02 15:21:53 UTC
Re: T 5.1 How to inject Spring beans by name?
Thx for the hint. I was lazy and wanted to scrap the added indirection of a
separare service layer for a small exploration app.
But the problem occurs in more places than only the transaction proxy
hiding.
In my latest project I use a couple of spring configured activemq/jms queues
which of course all resolve to Queue.class. I use the ApplicationContext
service for now, but it really seems odd to me, why there is no inbuilt
facility by which I can reference a Spring bean by name.
Spring itself utilizes the JSR compatible javax.annotation.Resource for
this.
Like in
@Autowired
@Resource(name = "mailQueue")
private Queue mailQueue = null;
@Autowired
@Resource(name = "feedQueue")
private Queue feedQueue = null;
Maybe that could be a way for Tapestry 5.2 also?
Regards,
Otho
2009/5/31 Jonathan Barker <jo...@gmail.com>
> Otho,
>
> Just in case you are still looking for a solution...
>
>
> Change how you declare your beans. For example:
>
> <bean id="txProxyTemplate" abstract="true"
>
>
> class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
> <property name="transactionManager">
> <ref local="transactionManager" />
> </property>
> <property name="transactionAttributes">
> <props>
> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
> <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
> <prop key="make*">PROPAGATION_REQUIRED</prop>
> <prop key="delete*">PROPAGATION_REQUIRED</prop>
> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
> </props>
> </property>
> </bean>
> <bean id="authorityDAO" parent="txProxyTemplate">
> <property name="target">
> <!-- This is how to hide the second implementer of the interface
> from Tapestry -->
> <bean
>
> class="ca.itstrategic.fmp.portal.persistence.hibernate.AuthorityDAOImpl">
> <property name="sessionFactory">
> <ref local="sessionFactory" />
> </property>
> </bean>
> </property>
> </bean>
>
>
> The key piece is how you specify the target of the
> TransactionProxyFactoryBean. By using a <bean> declaration rather than a
> reference to a bean, Tapestry only sees the outer proxy bean.
>
>
> Jonathan
>
>
> On Tue, Apr 7, 2009 at 1:58 PM, Otho <ta...@googlemail.com> wrote:
>
> > Since Spring beans are not exposed anymore as services I get exceptions
> > like
> >
> >
> > Error obtaining injected value for field org.example.user.Login.dao:
> Spring
> > context contains 2 beans assignable to type org.example.dao.Dao: dao,
> > daoImpl.
> >
> > I couldn't find anything in the docs about injecting by name. And the
> > proposes workaround for non singletons with injecting ApplicationContext
> > and
> > then get the bean by name/id works, but is a bit awkward in cases like
> > this.
> >
> > Is there some other possibility? If not, is support for injection by name
> > planned in the future without the 5.0 compatibility mode?
> >
>
>
>
> --
> Jonathan Barker
> ITStrategic
>