|
From: Estes, J. D - S. L. M. <jam...@us...> - 2004-06-04 13:34:55
|
I've been thinking about this quite a bit lately. My first instinct when using Spring was that I should be able to do this...but as I learned more about Spring and dependency injection, I felt it was not appropriate to be able to do includes in a bean file. What it amounts to is a dependency that you are allowing the bean file itself to seek out and resolve...instead of allowing the caller/container/environment do this for you by loading all the appropriate configs together (or through a parent hierarchy). Example: =20 You have an Application Context XML file that contains your DAO beans, but you want your JUnit tests to run with a different dataSource (dbcp) than your actual web application (jndi). So you have 3 xml files: the main dao xml, a dbcp dataSource xml file, and a jndi dataSource xml file. =20 With the include approach, my dao file would directly point to the implementation I want, and I would have to change it (or use ant to do it for me) when I switch between the 2 environments. =20 If I use the injection approach, my JUnit would setup a hierarchy with the dao xml and the dbcp dataSource xml by directly creating an instance of the ClassPathXmlApplicationContext with the 2 files as the configLocations. The Web Application would load the dao xml and the jndi dataSource xml via the configLocation (using classpath: pathname for the dao and normal file path for the jndi xml file). No complex changes are required for it to work in both instances. The dependencies are resolved appropriately by the application in use. It would be nice (for clarity/documentation purposes) to be able to define abstract beans in the file. Essentially a placeholder saying "I know this bean is not in this file, but it is assumed that it will be provided by another xml file in the same or parent container". And then possibly have a validation error when a container (once composed) does not have an 'implementation' for the bean. This essentially already happens by just referencing the bean, but again, the abstract bean would just be for clarity. I can, however see the need for more easily composing and packaging a set of bean files. If my dao project internally used several xml config files, I would not want to force the main project to know that much about the internals of the dao project (e.g. "To use this dao, pull the jar in and then create your spring application context with the following xml files present: classpath:com/foo/dao/DaoCore-context.xml, classpath:com/foo/dao/DaoFinance-context.xml, classpath:com/foo/dao/DaoUsers-context.xml, Classpath:com/foo/dao/DaoHibernate-context.xml). =20 For this kind of purpose, I think the include would be nice, but I would want to keep includes out of my actual bean files and have a special kind of composite bean file that has includes in it (or I would just keep them separate myself in practice, but I think it keeps things more clean this way). It would also be possible to have a springindex: type of path that would point to a special kind of bean file (on the classpath or in the file system) with a list/include of the bean config files that should be loaded from the classpath.=20 So for my example above, the dao would be in a jar along with a dao-index.xml file that pointed to each of the needed files. And I could include them all in my web application context with a config location of springindex:com/foo/dao/dao-index.xml. OR if Spring does allow include directives, I would (again keeping the include or composition file separate) have a config location of classpath:com/foo/dao/dao-index.xml. Just my thoughts. James |
|
From: <jue...@we...> - 2004-09-17 12:55:13
|
I'm not sure whether such a "transform-with" attribute would just apply =
to the import tag: This should be available for all XML bean definition =
files, not just for imported ones. The question is, how to specify the =
XSL file for a "contextConfigLocation" in web.xml, for example, or for a =
FileSystemXmlApplicationContext?
Juergen
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...]On Behalf
Of Andy Depue
Sent: Thursday, September 16, 2004 5:21 PM
To: spr...@li...
Subject: Re: [Springframework-developer] Import tag for XML bean
definitions
I like having this option. One thought this triggered in my head is the =
possibility of having application oriented XML config files. In other =
words,=20
config files that are oriented around your app so that they become =
easier to=20
work with for the masses. ActiveMQ and Mule are two systems that allow =
you=20
to either configure via Spring or configure via a native XML that is=20
typically easier to work with. ActiveMQ actually uses XSL internally to =
translate from the ActiveMQ oriented XML config to a Spring config. So, =
having said all this, would it make sense to add an xsl (or =
transform-with)=20
attribute to the import tag? I could then do something like this:
<beans>
<import resource=3D"app-config.xml" =
transform-with=3D"app-to-spring.xsl"/>
...
</beans>
Thoughts?
- Andy
On Thursday 16 September 2004 01:22 am, j=FCrgen h=F6ller [werk3AT] =
wrote:
> Hi everybody,
>
> During an extra evening I had to spend at an airport hotel in Rome, =
I've
> implemented an "import" tag for XML bean definitions:
>
> http://opensource.atlassian.com/projects/spring/browse/SPR-137
>
> Basically, you can put any number of "import" tags at the beginning of =
bean
> definition files:
>
> <beans>
>
> <import resource=3D"myImport1.xml"/>
> <import resource=3D"myImport2.xml"/>
>
> <bean ... />
>
> </beans>
>
> The resource locations are interpreted as relative to the file that
> contains the import tags. Effectively, this is delegated to the
> "createRelative" method on the Resource interface, invoked on the =
Resource
> object for the containing file. ("createRelative" has already been
> introduced in 1.1 final.)
>
> I'll commit this tonight, provided that there aren't any objections. =
While
> I'm not gonna recommend this feature too much, as I personally prefer =
a
> "contextConfigLocation" that refers to multiple files, I still believe =
that
> an import tag is a useful addition. In particular, some people are =
used to
> such a feature from Ant and XWork...
>
> Juergen
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
> Project Admins to receive an Apple iPod Mini FREE for your judgement =
on
> who ports your project to Linux PPC the best. Sponsored by IBM.
> Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|
|
From: <jue...@we...> - 2004-09-17 12:57:32
|
I can certainly add support for a delimited list of resource locations. = However, you will not be able to use a PropertyPlaceholderConfigurer for = those locations: Such BeanFactoryPostProcessors get applied after all = bean definitions have been registered. And I don't see a chance to = change this with the current semantics... Juergen -----Original Message----- From: spr...@li... [mailto:spr...@li...]On Behalf Of bryan Sent: Thursday, September 16, 2004 6:04 PM To: spr...@li... Subject: Re: [Springframework-developer] Import tag for XML bean definitions juergen .... you are a legend !!!!=20 Hey one thing though .. Would it be possible to allow the user to specify a list like=20 so .......=20 <import resource=3D"myImport1.xml,myImport2.xml,myImport3.xml"/> The reason that this would be *super* *super* usefull is because then=20 users could store these values in a properties file or in the registry using the Preferences API and then use the property placeholder=20 configurer to fill in the blanks at runtime.=20 On other thing ..... if you wanted to be super smart and really show off = heres a cool feature ....=20 <beans> <if value=3D"test" equals=3D"test"> <import resource=3D"myImport1.xml"/> </if> <bean ... /> </beans> --b On Thu, 16 Sep 2004 10:22:12 +0200, j=FCrgen h=F6ller [ werk3AT ] <jue...@we...> wrote: > Hi everybody, >=20 > During an extra evening I had to spend at an airport hotel in Rome, = I've implemented an "import" tag for XML bean definitions: >=20 > http://opensource.atlassian.com/projects/spring/browse/SPR-137 >=20 > Basically, you can put any number of "import" tags at the beginning of = bean definition files: >=20 > <beans> >=20 > <import resource=3D"myImport1.xml"/> > <import resource=3D"myImport2.xml"/> >=20 > <bean ... /> >=20 > </beans> >=20 > The resource locations are interpreted as relative to the file that = contains the import tags. Effectively, this is delegated to the = "createRelative" method on the Resource interface, invoked on the = Resource object for the containing file. ("createRelative" has already = been introduced in 1.1 final.) >=20 > I'll commit this tonight, provided that there aren't any objections. = While I'm not gonna recommend this feature too much, as I personally = prefer a "contextConfigLocation" that refers to multiple files, I still = believe that an import tag is a useful addition. In particular, some = people are used to such a feature from Ant and XWork... >=20 > Juergen >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 > Project Admins to receive an Apple iPod Mini FREE for your judgement = on > who ports your project to Linux PPC the best. Sponsored by IBM. > Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |
|
From: bryan <nih...@gm...> - 2004-09-17 13:15:54
|
It is true, i tried implementing this myself and had no success. It is caused by the fact that "Bean definitions in ancestor contexts are visible to descendant contexts but never the reverse" ... is there a specific reaso= n=20 for this apart from preventing endless loops etc ?=20 --b On Fri, 17 Sep 2004 14:57:47 +0200, j=FCrgen h=F6ller [ werk3AT ] <jue...@we...> wrote: > I can certainly add support for a delimited list of resource locations. H= owever, you will not be able to use a PropertyPlaceholderConfigurer for tho= se locations: Such BeanFactoryPostProcessors get applied after all bean def= initions have been registered. And I don't see a chance to change this with= the current semantics... >=20 > Juergen >=20 >=20 > -----Original Message----- > From: spr...@li... > [mailto:spr...@li...]On Behalf > Of bryan > Sent: Thursday, September 16, 2004 6:04 PM > To: spr...@li... > Subject: Re: [Springframework-developer] Import tag for XML bean > definitions >=20 > juergen .... you are a legend !!!! >=20 > Hey one thing though .. >=20 > Would it be possible to allow the user to specify a list like > so ....... >=20 > <import resource=3D"myImport1.xml,myImport2.xml,myImport3.xml"/> >=20 > The reason that this would be *super* *super* usefull is because then > users could store these values in a properties file or in the registry > using the Preferences API and then use the property placeholder > configurer to fill in the blanks at runtime. >=20 > On other thing ..... if you wanted to be super smart and really show off > heres a cool feature .... >=20 > <beans> > <if value=3D"test" equals=3D"test"> > <import resource=3D"myImport1.xml"/> > </if> >=20 > <bean ... /> >=20 > </beans> >=20 > --b >=20 > On Thu, 16 Sep 2004 10:22:12 +0200, j=FCrgen h=F6ller [ werk3AT ] >=20 >=20 > <jue...@we...> wrote: > > Hi everybody, > > > > During an extra evening I had to spend at an airport hotel in Rome, I'v= e implemented an "import" tag for XML bean definitions: > > > > http://opensource.atlassian.com/projects/spring/browse/SPR-137 > > > > Basically, you can put any number of "import" tags at the beginning of = bean definition files: > > > > <beans> > > > > <import resource=3D"myImport1.xml"/> > > <import resource=3D"myImport2.xml"/> > > > > <bean ... /> > > > > </beans> > > > > The resource locations are interpreted as relative to the file that con= tains the import tags. Effectively, this is delegated to the "createRelativ= e" method on the Resource interface, invoked on the Resource object for the= containing file. ("createRelative" has already been introduced in 1.1 fina= l.) > > > > I'll commit this tonight, provided that there aren't any objections. Wh= ile I'm not gonna recommend this feature too much, as I personally prefer a= "contextConfigLocation" that refers to multiple files, I still believe tha= t an import tag is a useful addition. In particular, some people are used t= o such a feature from Ant and XWork... > > > > Juergen > > > > ------------------------------------------------------- > > This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 > > Project Admins to receive an Apple iPod Mini FREE for your judgement on > > who ports your project to Linux PPC the best. Sponsored by IBM. > > Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php > > _______________________________________________ > > Springframework-developer mailing list > > Spr...@li... > > https://lists.sourceforge.net/lists/listinfo/springframework-developer > > >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 > Project Admins to receive an Apple iPod Mini FREE for your judgement on > who ports your project to Linux PPC the best. Sponsored by IBM. > Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 > Project Admins to receive an Apple iPod Mini FREE for your judgement on > who ports your project to Linux PPC the best. Sponsored by IBM. > Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > |
|
From: <jue...@we...> - 2004-09-17 13:02:49
|
I personally prefer to specify multiple bean definitions files via a =
"contextConfigLocation" that contains multiple resource paths. This =
allows to drive combinations through that init-param, without having to =
touch the bean definition files themselves: for example, to easily =
switch between "dataAccessContext-hibernate.xml" and =
"dataAccessContext-jdbc.xml".
I guess it boils down to a matter of taste: Both ways have their =
individual merits. That's why I finally added the "import" tag (which is =
still not committed, BTW - will do so tonight).
If a single file gets loaded multiple times for a single context, later =
bean definitions will simply replace existing ones of the same name. =
There is no explicit check for duplicate files: This rather works at the =
individual bean definition level.
Juergen
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...]On Behalf
Of Keith
Sent: Thursday, September 16, 2004 4:34 PM
To: spr...@li...
Subject: RE: [Springframework-developer] Import tag for XML bean
definitions
This sounds great! Just curious, why wouldn't you recommend it too =
much? =20
I know I've had mention before people wanting to see logically how the =
files
are related - when they're looking at the files (rather than going to
bootstrap configuration, generally separate.) Kind of a "less magic" =
thing.
I think the import tag, like the recent abstract attribute for abstract =
bean
definitions, can help make things more explicit.
<beans description=3D"Business layer services definitions">
<import resource=3D"data-access.xml"
description=3D"Import dependent DAO definitions"/>
<bean> ... </bean>
...
</beans>
Just curious: if I was to do like above, and still bootstrap a single
application context with "business-layer.xml" and "data-access.xml" as
opposed to just "business-layer" - what happens?
Let's say I had a "utilities-context.xml" with utility beans used by my
other contexts (like PropertyPlaceholderConfigurer), used by business =
and
dao. If I imported that guy into those files, but in the end everything
resulted in a flat "big" context -- what would happen?
Getting code churned out at the airport is the best! :-) Keith=20
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...] On Behalf =
Of
j=FCrgen h=F6ller [werk3AT]
Sent: Thursday, September 16, 2004 4:22 AM
To: spr...@li...
Subject: [Springframework-developer] Import tag for XML bean definitions
Hi everybody,
During an extra evening I had to spend at an airport hotel in Rome, I've
implemented an "import" tag for XML bean definitions:
http://opensource.atlassian.com/projects/spring/browse/SPR-137
Basically, you can put any number of "import" tags at the beginning of =
bean
definition files:
<beans>
<import resource=3D"myImport1.xml"/>
<import resource=3D"myImport2.xml"/>
<bean ... />
</beans>
The resource locations are interpreted as relative to the file that =
contains
the import tags. Effectively, this is delegated to the "createRelative"
method on the Resource interface, invoked on the Resource object for the
containing file. ("createRelative" has already been introduced in 1.1
final.)
I'll commit this tonight, provided that there aren't any objections. =
While
I'm not gonna recommend this feature too much, as I personally prefer a
"contextConfigLocation" that refers to multiple files, I still believe =
that
an import tag is a useful addition. In particular, some people are used =
to
such a feature from Ant and XWork...
Juergen
-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|
|
From: Tom T. <tom...@pr...> - 2004-06-04 14:43:32
|
> So for my example above, the dao would be in a jar along with a > dao-index.xml file that pointed to each of the needed files. And I > could include them all in my web application context with a config > location of springindex:com/foo/dao/dao-index.xml. OR if Spring does > allow include directives, I would (again keeping the include or > composition file separate) have a config location of > classpath:com/foo/dao/dao-index.xml. I don't think this will work: "classpath:" denotes a resource *location* while "springindex:" denotes a *type*... Good point though, to limit the import functionality to a "composed bean definitions file"-definition. Tom. |
|
From: Kirill M. <ki...@ma...> - 2004-06-04 15:59:01
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Estes, James D - St. Louis, MO wrote: | Example: | You have an Application Context XML file that contains your DAO beans, | but you want your JUnit tests to run with a different dataSource (dbcp) | than your actual web application (jndi). So you have 3 xml files: the | main dao xml, a dbcp dataSource xml file, and a jndi dataSource xml | file. | With the include approach, my dao file would directly point to the | implementation I want, and I would have to change it (or use ant to do | it for me) when I switch between the 2 environments. ~ To be honest, I've imlemented the import just for this situation. ~ But from the other side - I have 2 main Application Context XML files - ~ one for tests and one for production. Each contains dataSource specifics. ~ And each includes "generic" configuraton file which contains beans common ~ for these two environments. ~ So no need to switch et all. ~ Regards, ~ KIR - -- Kirill Maximov (aka KIR) | http://www.maxkir.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFAwJw9E0YZ3264U5QRAhTuAJ4iuNEsTaawQ9/9+A3DDvahQDOV8gCfSQoY edchfor67HVIWM5RYGoNqQ8= =320W -----END PGP SIGNATURE----- |