From bb3c9c189886a1a251cfb3dc977ce0828ac17a29 Mon Sep 17 00:00:00 2001 From: Mark Pollack Date: Fri, 19 Jun 2009 13:43:33 +0000 Subject: [PATCH] clean up use of old usage. Refer to STS and p-namespace --- spring-framework-reference/src/beans.xml | 116 ++++++++++++----------- 1 file changed, 61 insertions(+), 55 deletions(-) diff --git a/spring-framework-reference/src/beans.xml b/spring-framework-reference/src/beans.xml index ad22eef9aa0..18d00b95129 100644 --- a/spring-framework-reference/src/beans.xml +++ b/spring-framework-reference/src/beans.xml @@ -23,11 +23,10 @@ interface builds on top of the BeanFactory (it is a sub-interface) and adds other functionality such as easier integration with Spring's AOP features, message resource handling (for use - in internationalization), event propagation, and application-layer - in internationalization), event publication, and application-layer - specific contexts such as the - WebApplicationContext for use in web - applications. + in internationalization), event propagation, and application-layer in + internationalization), event publication, and application-layer specific + contexts such as the WebApplicationContext + for use in web applications. In short, the BeanFactory provides the configuration framework and basic functionality, while the @@ -249,7 +248,7 @@ the chapter entitled . - The services.xml configuration file is + The services.xml configuration file is <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" @@ -301,7 +300,7 @@ that the property element refers to the name of JavaBean property and the ref element refers to the name of another bean definition. This linkage between id and ref - elements expresses the dependency between collaborating objects. + elements expresses the dependency between collaborating objects.
Composing XML-based configuration metadata @@ -1292,9 +1291,9 @@ public class ExampleBean { Straight values (primitives, <literal>Strings</literal>, etc.) - The <value/> element specifies a - property or constructor argument as a human-readable string - representation. The value attribute of the + <property/> element specifies a property or + constructor argument as a human-readable string representation. As mentioned previously, JavaBeans PropertyEditors are used to convert these string values from a @@ -1303,30 +1302,6 @@ public class ExampleBean { <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> - <!-- results in a setDriverClassName(String) call --> - <property name="driverClassName"> - <value>com.mysql.jdbc.Driver</value> - </property> - <property name="url"> - <value>jdbc:mysql://localhost:3306/mydb</value> - </property> - <property name="username"> - <value>root</value> - </property> - <property name="password"> - <value>masterkaoli</value> - </property> -</bean> - - The <property/> and - <constructor-arg/> elements also support the - use of the 'value' attribute, which can lead to - much more succinct configuration. When using the - 'value' attribute, the above bean definition reads - like so: - - <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> - <!-- results in a setDriverClassName(String) call --> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/mydb"/> @@ -1334,12 +1309,42 @@ public class ExampleBean { <property name="password" value="masterkaoli"/> </bean> - The Spring team generally prefer the attribute style over the - use of nested <value/> elements. If you are - reading this reference manual straight through from top to bottom - (wow!) then we are getting slightly ahead of ourselves here, but you - can also configure a java.util.Properties - instance like so: + You can also use the p-namespace for even more succinct + XML configuration. + + <beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:p="http://www.springframework.org/schema/p" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> + + <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" + p:driverClassName="com.mysql.jdbc.Driver" + p:url="jdbc:mysql://localhost:3306/mydb" + p:username="root" + p:password="masterkaoli"/> + + +</beans> + + + + While the XML is in a more succinct form, there is still an + issue with authoring any XML based bean definition which is how to + ensure you do not make any typos for property names. Any typos will be + discovered at runtime, not design time unless you are using an IDE + such as IntelliJ + IDEA or the SpringSource Tool + Suite (STS) that support automatic property completion when + defining bean definitions. The use of such IDE assistance is highly + recommended. + + If you are reading this reference manual straight through from + top to bottom (wow!) then we are getting slightly ahead of ourselves + here, but you can also configure a + java.util.Properties instance like so: <bean id="mappings" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> @@ -1750,7 +1755,7 @@ support=support@example.co.uk value ("") <bean class="ExampleBean"> - <property name="email"><value/></property> + <property name="email" value=""/> </bean> This is equivalent to the following Java code: @@ -2705,8 +2710,8 @@ public class ReplacementComputeValue implements MethodReplacer { linkend="beans-factory-scopes-session">session - Scopes a single bean definition to the lifecycle of an - HTTP Session. Only valid in the + Scopes a single bean definition to the lifecycle of + an HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext. @@ -3986,8 +3991,8 @@ public final class Boot { BeanPostProcessor interface, and register them as post-processors, to be then called appropriately by the container on bean creation. Nothing else needs to be done other than - deploying the post-processors in a similar fashion to any other bean. - + deploying the post-processors in a similar fashion to any other + bean. <interfacename>BeanPostProcessors</interfacename> and AOP @@ -6458,7 +6463,8 @@ public class AppConfig { <title>Specifying bean scope
- Using the <interfacename>@Scope</interfacename> annotation + Using the <interfacename>@Scope</interfacename> + annotation You can specify that your beans defined with the @Bean annotation should have a @@ -6466,11 +6472,9 @@ public class AppConfig { the Bean Scopes section. - The default scope is "singleton", but - this can be overridden by using the - @Scope annotation: -@Configuration + The default scope is "singleton", but this + can be overridden by using the @Scope + annotation: @Configuration public class MyConfiguration { @Bean @Scope("prototype") @@ -6538,9 +6542,9 @@ public Service userService() { Using Java-configuration support we can easily create a subclass of CommandManager where the abstract - createCommand() method is overridden in such a way that it - 'looks up' a brand new (prototype) command object: @Bean + createCommand() method is overridden in such a way that + it 'looks up' a brand new (prototype) command object: + @Bean @Scope("prototype") public AsyncCommand asyncCommand() { AsyncCommand command = new AsyncCommand(); @@ -6594,7 +6598,7 @@ public class AppConfig { frameworks that integrate with Spring. Often third-party components that can not use more modern equivalents such as @PostConstruct or @PreDestroy in order to remain compatible with JDK 1.4 or avoid a dependency on - JSR-250. + JSR-250. This section provides some additional background into the differences between the BeanFactory and ApplicationContext and how one @@ -6652,6 +6656,7 @@ public class AppConfig { align="center">ApplicationContext + Bean instantiation/wiring @@ -6690,6 +6695,7 @@ public class AppConfig { Yes + ApplicationEvent publication