[ 
https://issues.apache.org/struts/browse/TILES-387?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45809#action_45809
 ] 

Bjorn Harvold commented on TILES-387:
-------------------------------------

Within OSGi you always have to be careful about instantiating classes using 
reflection for this very reason. The easiest would probably be to have all the 
factories and the class loader in the same bundle. However, if that doesn't 
make sense, you probably want to have a class loader in every bundle where 
there is a factory to be instantiated. The last option, which I was fiddling 
around with, was to have my own bundle instantiate the factory as my bundle 
both imported tiles-api and tiles-servlet. That's pretty easy when 
instantiating AbstractTilesApplicationContextFactory but not as easy when 
instantiating AbstractTilesContainerFactory because of the initialization that 
takes place.

The Felix Maven plugin is the way to go. You shouldn't change the imports as it 
doesn't make sense for tiles-api to rely on tiles-servlet or any of the other 
bundles for that matter so you can leave the configuration as it is.

Cheers
bjorn

> Creating a tilesConfigurer for Spring Web does not work in an OSGi environment
> ------------------------------------------------------------------------------
>
>                 Key: TILES-387
>                 URL: https://issues.apache.org/struts/browse/TILES-387
>             Project: Tiles
>          Issue Type: Bug
>          Components: tiles-api, tiles-servlet
>    Affects Versions: 2.1.2
>         Environment: Any
>            Reporter: Bjorn Harvold
>
> As of Tiles 2.1.1, the TilesConfigurer that was written by the Spring guys no 
> longer works as they are using deprecated attributes in Tiles. They are 
> working on a new tiles configurer for v3 of Spring. In the meantime, there 
> have been some solutions submitted by the community. They work in a regular 
> environment but not within an OSGi environment. 
> (see here for details on the issue raised: 
> http://jira.springframework.org/browse/SPR-5411)
> The problem is this:
> public SpringTilesConfigurer() {
>         this.tilesPropertyMap.put(
>                 
> AbstractTilesApplicationContextFactory.APPLICATION_CONTEXT_FACTORY_INIT_PARAM,
>                 
> WildcardServletTilesApplicationContextFactory.class.getName());
>         this.tilesPropertyMap.put(
>                 TilesContainerFactory.PREPARER_FACTORY_INIT_PARAM,
>                 BasicPreparerFactory.class.getName());
>         this.tilesPropertyMap.put(
>                 DefinitionsFactory.LOCALE_RESOLVER_IMPL_PROPERTY,
>                 SpringLocaleResolver.class.getName());
>         
> this.tilesPropertyMap.put(TilesContainerFactory.ATTRIBUTE_EVALUATOR_INIT_PARAM,
>  ELAttributeEvaluator.class.getName());
>         
> this.tilesPropertyMap.put(TilesContainerFactory.CONTAINER_FACTORY_MUTABLE_INIT_PARAM,
>                 Boolean.toString(false));
>     }
> protected TilesContainer createTilesContainer() throws TilesException {
>         ServletContextAdapter adaptedContext = new ServletContextAdapter(new 
> DelegatingServletConfig());
>         TilesApplicationContext preliminaryContext = new 
> ServletTilesApplicationContext(adaptedContext);
>         AbstractTilesApplicationContextFactory contextFactory = 
> AbstractTilesApplicationContextFactory.createFactory(preliminaryContext);
>         this.tilesContext = 
> contextFactory.createApplicationContext(adaptedContext);
>         AbstractTilesContainerFactory factory = 
> AbstractTilesContainerFactory.getTilesContainerFactory(this.tilesContext);
>         return factory.createContainer(this.tilesContext);
>     } 
> When trying to create the context factory, it will try to initialize 
> WildcardServletTilesApplicationContextFactory in 
> AbstractTilesApplicationContextFactory:80 with the help of ClassUtil. Now 
> WildcardServletTilesApplicationContextFactory is located in the tiles-servlet 
> bundle while ClassUtil is located in tiles-api. Tiles-api does not have an 
> import dependency on tiles-servlet (as it should be) so when ClassUtil tries 
> to instantiate the class it cannot find it. This problem also occurs when 
> trying to instantiate the TilesContainerFactory.
> Is there something the Tiles team needs to do in order to make this a work 
> within OSGi or is the Spring community going at it the wrong way?
> Cheers
> bjorn

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to