[Hippo-cms7-user] Spring integration without SimpleDispatcherHstComponent

Ard Schrijvers a.schrijvers at onehippo.com
Mon Apr 16 10:35:45 CEST 2012


On Mon, Apr 16, 2012 at 10:25 AM, David Martin <dmartin at ippon.fr> wrote:
> Hi,
>
> Thanks for your reply. Let me first answer your question.
> My main goal is not to instantiate the spring component for every hst
> component instance. That's not the spirit of Spring :)
> My goal is to have a configuration that provide dependency injection using
> annotations (]Autowired or @Inject) of Spring beans directly into HST
> component, without having to code anything special in HST component.

Ah nice. Seems good to me. You cannot wire request specific parts on
the HST, but as long as it are 'global' components only instantiated
once for a HstComponent, this seems like a nice way to do it

> Using AspectJ, each HST component receives the glue code that does exactly
> this job.
>
> But I wasn't aware of the class you are talking about
> (ClientSpringComponentManager). I'm going to read more about it, but as I
> understand it, a HST component has to have the lookup code in order to
> inject the Spring bean (compManager.getComponent(someClass.class)), which
> is, from my point of view still too much intrusive (compared to a simple
> annotation on a private attribute of the HST component).
>
> The drawback (or at least one of them if many) of my solution is that I have
> to modify the maven build chain to add the AspectJ magic (compile-time
> bytecode modification : I don't like load-time weaving...).

Modifying the maven build doesn't seem to harmful to me.

Regards ard

>
> Glad to share my point of view with you anyway ! Feel free to ask me
> anything about this or give me some other hints about spring integration.
> I'm still a noob when talking about Hippo ;)
>
> David
>
> On Sat, Apr 14, 2012 at 5:09 PM, Ard Schrijvers <a.schrijvers at onehippo.com>
> wrote:
>>
>> Hello David,
>>
>> thank you very much for your feedback, much appreciated.
>>
>> However, I also have a question : You want the spring component to be
>> instantiated per HstComponent? Note that one HstComponent class will
>> be instantiated once *per* hst component configuration that uses the
>> class. Not sure if that is desirable for you.
>>
>> You can from a HstComponent always access 'global' spring components
>> throught:
>>
>> HstService.getComponentManager().getComponent('....')
>>
>> Also, for developers, we have enabled a ClientSpringComponentManager
>> through which you can manage your own spring (non hst core)
>> components. Also see [1]
>>
>> Not sure if this is what you tried to solve, either way, hope it might
>> help
>>
>> Thanks again for your feedback
>>
>> Regards Ard
>>
>> [1]
>> https://wiki.onehippo.com/display/CMS7/Using+the+Spring+ClientComponent
>>
>> On Thu, Apr 12, 2012 at 6:50 PM, David Martin <dmartin at ippon.fr> wrote:
>> > Hi,
>> >
>> > I'd like you to share your point of view about the way I've adopted to
>> > inject Spring beans into some Hippo components...
>> > It works as expected, so no problem here. I just want to be sure this
>> > doesn't break any Hippo rules I may not know.
>> >
>> > a) I've set up a Spring root context with the well known Spring listener
>> > : ContextLoaderListener
>> > b) I've declared in the root application context descriptor file the
>> > aspectj
>> > related stuff : <context:spring-configured/>
>> > c) I've annoted my custom component (which extends BaseHstComponent)
>> > with
>> > the @Configurable annotation :
>> > @Configurable(autowire=Autowire.BY_TYPE)
>> > d) I've added a property to this component with an @Autowired annotation
>> > (this property should be initialized with an object coming from  the
>> > spring
>> > context)
>> > e) I've modified my maven module's pom like this :
>> > <dependency>
>> >    <groupId>org.aspectj</groupId>
>> >    <artifactId>aspectjrt</artifactId>
>> >    <version>1.6.11</version>
>> > </dependency>
>> >     <dependency>
>> >       <groupId>org.springframework</groupId>
>> >       <artifactId>spring-aspects</artifactId>
>> >       <version>${spring.version}</version>
>> >       <scope>compile</scope>
>> >     </dependency>
>> >
>> >     <!-- These two dependencies are needed because of Spring Aspects /
>> > AspectJ respectively ... -->
>> >     <dependency>
>> >       <groupId>org.springframework</groupId>
>> >       <artifactId>spring-tx</artifactId>
>> >       <version>${spring.version}</version>
>> >       <scope>compile</scope>
>> >     </dependency>
>> > <dependency>
>> >  <groupId>javax.persistence</groupId>
>> >  <artifactId>persistence-api</artifactId>
>> >  <version>1.0</version>
>> >  <scope>provided</scope>
>> > </dependency>
>> > [...]
>> >       <plugin>
>> >           <groupId>org.codehaus.mojo</groupId>
>> >           <artifactId>aspectj-maven-plugin</artifactId>
>> >           <version>1.4</version>
>> >           <configuration>
>> >               <complianceLevel>1.6</complianceLevel>
>> >               <aspectLibraries>
>> >                   <aspectLibrary>
>> >                       <groupId>org.springframework</groupId>
>> >                       <artifactId>spring-aspects</artifactId>
>> >                   </aspectLibrary>
>> >               </aspectLibraries>
>> >           </configuration>
>> >           <executions>
>> >               <execution>
>> >                   <goals>
>> >                       <goal>compile</goal>
>> >                   </goals>
>> >               </execution>
>> >           </executions>
>> >       </plugin>
>> > <plugin>
>> >    <artifactId>maven-eclipse-plugin</artifactId>
>> >    <version>2.8</version>
>> >    <configuration>
>> >        <ajdtVersion>1.5</ajdtVersion>
>> >    </configuration>
>> > </plugin>
>> >
>> > f) that's it, my component, even if not managed by Spring, has its
>> > property
>> > initialized with the right Spring bean. It works with eclipse+jrebel as
>> > well.
>> >
>> > David
>> >
>> > _______________________________________________
>> > Hippo-cms7-user mailing list and forums
>> > http://www.onehippo.org/cms7/support/forums.html
>>
>>
>>
>> --
>> Amsterdam - Oosteinde 11, 1017 WT Amsterdam
>> Boston - 1 Broadway, Cambridge, MA 02142
>>
>> US +1 877 414 4776 (toll free)
>> Europe +31(0)20 522 4466
>> www.onehippo.com
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/forums.html
>
>
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html



-- 
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com



More information about the Hippo-cms7-user mailing list