Fixed whitespace and added private modifiers to @Value-annotated fields in the @Configuration example

This commit is contained in:
Chris Beams 2009-04-18 00:22:03 +00:00
parent 8aface8e5d
commit c78f9d14fa
1 changed files with 23 additions and 24 deletions

View File

@ -312,35 +312,34 @@ public class RewardsTestDatabase {
</itemizedlist></para> </itemizedlist></para>
<para>Here is an example of a Java class providing basic configuration <para>Here is an example of a Java class providing basic configuration
using the new JavaConfig features: <programlisting language="java">@Configuration using the new JavaConfig features: <programlisting language="java">@Configuration
public class AppConfig{ public class AppConfig{
@Value("#{jdbcProperties.url}") String jdbcUrl; private @Value("#{jdbcProperties.url}") String jdbcUrl;
@Value("#{jdbcProperties.username}") String username; private @Value("#{jdbcProperties.username}") String username;
@Value("#{jdbcProperties.password}") String password; private @Value("#{jdbcProperties.password}") String password;
@Bean @Bean
public FooServicefooService() { public FooService fooService() {
return new FooServiceImpl(fooRepository()); return new FooServiceImpl(fooRepository());
} }
@Bean @Bean
public FooRepositoryfooRepository() { public FooRepository fooRepository() {
return new HibernateFooRepository(sessionFactory()); return new HibernateFooRepository(sessionFactory());
} }
@Bean @Bean
public SessionFactorysessionFactory() { public SessionFactory sessionFactory() {
// wire up a session factory using // wire up a session factory using
// AnnotationSessionFactoryBean // AnnotationSessionFactoryBean
asFactoryBean.setDataSource(dataSource()); asFactoryBean.setDataSource(dataSource());
return (SessionFactory) asFactoryBean.getObject(); return (SessionFactory) asFactoryBean.getObject();
} }
@Bean @Bean
public DataSourcedataSource() { public DataSource dataSource() {
return new DriverManagerDataSource(jdbcUrl, return new DriverManagerDataSource(jdbcUrl, username, password);
username, password); }
}
} }
</programlisting> To get this to work you need to add the following component </programlisting> To get this to work you need to add the following component
scanning entry in your minimal application context XML file. scanning entry in your minimal application context XML file.
@ -431,4 +430,4 @@ public class AppConfig{
<para>Work in progress... not part of the Spring 3.0 M3 release.</para> <para>Work in progress... not part of the Spring 3.0 M3 release.</para>
</section> </section>
</section> </section>
</chapter> </chapter>