Skip to content

Commit c78f9d1

Browse files
committed
Fixed whitespace and added private modifiers to @Value-annotated fields in the @configuration example
1 parent 8aface8 commit c78f9d1

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

spring-framework-reference/src/new-in-3.xml

+25-26
Original file line numberDiff line numberDiff line change
@@ -312,35 +312,34 @@ public class RewardsTestDatabase {
312312
</itemizedlist></para>
313313

314314
<para>Here is an example of a Java class providing basic configuration
315-
using the new JavaConfig features: <programlisting language="java">@Configuration
316-
public class AppConfig{
317-
@Value("#{jdbcProperties.url}") String jdbcUrl;
318-
@Value("#{jdbcProperties.username}") String username;
319-
@Value("#{jdbcProperties.password}") String password;
320-
321-
@Bean
322-
public FooServicefooService() {
323-
return new FooServiceImpl(fooRepository());
315+
using the new JavaConfig features: <programlisting language="java">@Configuration
316+
public class AppConfig{
317+
private @Value("#{jdbcProperties.url}") String jdbcUrl;
318+
private @Value("#{jdbcProperties.username}") String username;
319+
private @Value("#{jdbcProperties.password}") String password;
320+
321+
@Bean
322+
public FooService fooService() {
323+
return new FooServiceImpl(fooRepository());
324324
}
325325

326-
@Bean
327-
public FooRepositoryfooRepository() {
328-
return new HibernateFooRepository(sessionFactory());
326+
@Bean
327+
public FooRepository fooRepository() {
328+
return new HibernateFooRepository(sessionFactory());
329329
}
330330

331-
@Bean
332-
public SessionFactorysessionFactory() {
333-
// wire up a session factory using
334-
// AnnotationSessionFactoryBean
335-
asFactoryBean.setDataSource(dataSource());
336-
return (SessionFactory) asFactoryBean.getObject();
337-
}
338-
339-
@Bean
340-
public DataSourcedataSource() {
341-
return new DriverManagerDataSource(jdbcUrl,
342-
username, password);
343-
}
331+
@Bean
332+
public SessionFactory sessionFactory() {
333+
// wire up a session factory using
334+
// AnnotationSessionFactoryBean
335+
asFactoryBean.setDataSource(dataSource());
336+
return (SessionFactory) asFactoryBean.getObject();
337+
}
338+
339+
@Bean
340+
public DataSource dataSource() {
341+
return new DriverManagerDataSource(jdbcUrl, username, password);
342+
}
344343
}
345344
</programlisting> To get this to work you need to add the following component
346345
scanning entry in your minimal application context XML file.
@@ -431,4 +430,4 @@ public class AppConfig{
431430
<para>Work in progress... not part of the Spring 3.0 M3 release.</para>
432431
</section>
433432
</section>
434-
</chapter>
433+
</chapter>

0 commit comments

Comments
 (0)