|
From: Yan P. <ypu...@li...> - 2008-04-24 14:06:38
|
Hello I am new to this list but have been working with spring for several years now. I work at a company called LinkedIn and we use spring extensively (I can count over 1000 spring files in our source code as of today)... Very early on when spring was not as easily extensible (prior to 2.0) we actually extended it by inheriting a lot of classes (we basically wanted the ability to have our own tags in xml files). Then when namespace handling came along we created our own namespace and were able to get rid of all the custom extensions we had done. I am pretty familiar with the spring source code since I had to extend it in several ways in the past. I created the following Jira enhacement [http:// jira.springframework.org/browse/SPR-4729] and posted a patch that implements it. Like I mention in my comment in the jira ticket, I think that the concept of namespace is an amazing way to tailor the behavior of spring to our needs without having to hook ourselves deep in the framework. The two examples that I currently have on top of my head are: * like spring offers a set of custom property editors, we have a set of custom property editors for types that our company use (like MemorySize, Timespan... which allow us to write "30g" or "3h20m" in our spring files) * we also have our own set of lifecycle interfaces. Spring offers DisposableBean, our company has its own version. We want that those beans that we create with our own interface get disposed properly (One of the beauty of spring is that you should be able to use it without having your code depend on it) I know that I can do both of these things by 'registering' custom property editors and BeanPostProcessor. I obviously don't want to have to do that in every single spring file... I can obviously write my own tag <linkedIn:init/> that can do the trick, but it is one more thing to remember to add to the spring file and if you don't then suddenly the lifecycle does not work. What I think would be awesome is if I could do this by simply registering the namespace <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lin="http://www.linkedin.com/lispring" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.linkedin.com/lispring http:// www.linkedin.com/lispring/lispring.xsd"> </beans> The problem is that today the init() method on NamespaceHandler does not take any argument. What I suggest as an enhancement is to simply take an initializing context which at least gives access to the bean registry, so that we can 'tweak' it before even any bean is registered. The patch I posted is doing just that but most likely not in the best way, it was just a try. There are many many ways to do it, especially if we want to remain backward compatible. (For example we could create a NameSpaceHandlerInitContext class instead of passing the class I am currently providing...) So I would just like to know: a) what do you guys think about this change ? b) if you think it is ok to change it, I am entirely ok to implement it the way it needs to be and post a patch to be integrated in the source code. But I just need to know what is the 'correct' way to implement it. As a side note, we just started to use osgi and by simply creating a bundle with our custom spring namespace, it works magically with spring dm... Thanks in adavance Yan Pujante Distinguished Software Engineer, LinkedIn Corporation http://www.linkedin.com/in/yan |