Skip to content

Commit 73dfa9a

Browse files
committed
Polishing
1 parent 5a66a33 commit 73dfa9a

File tree

4 files changed

+45
-35
lines changed

4 files changed

+45
-35
lines changed

spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlListableBeanFactoryTests.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,30 +42,33 @@
4242
* @author Juergen Hoeller
4343
* @since 09.11.2003
4444
*/
45-
@SuppressWarnings({ "rawtypes", "unchecked" })
45+
@SuppressWarnings({"rawtypes", "unchecked"})
4646
public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTests {
4747

4848
private DefaultListableBeanFactory parent;
4949

5050
private DefaultListableBeanFactory factory;
5151

52+
5253
@Before
53-
public void setUp() {
54+
public void setup() {
5455
parent = new DefaultListableBeanFactory();
55-
Map m = new HashMap();
56-
m.put("name", "Albert");
56+
57+
Map map = new HashMap();
58+
map.put("name", "Albert");
5759
RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
58-
bd1.setPropertyValues(new MutablePropertyValues(m));
60+
bd1.setPropertyValues(new MutablePropertyValues(map));
5961
parent.registerBeanDefinition("father", bd1);
60-
m = new HashMap();
61-
m.put("name", "Roderick");
62+
63+
map = new HashMap();
64+
map.put("name", "Roderick");
6265
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
63-
bd2.setPropertyValues(new MutablePropertyValues(m));
66+
bd2.setPropertyValues(new MutablePropertyValues(map));
6467
parent.registerBeanDefinition("rod", bd2);
6568

6669
this.factory = new DefaultListableBeanFactory(parent);
67-
new XmlBeanDefinitionReader(this.factory).loadBeanDefinitions(
68-
new ClassPathResource("test.xml", getClass()));
70+
new XmlBeanDefinitionReader(this.factory).loadBeanDefinitions(new ClassPathResource("test.xml", getClass()));
71+
6972
this.factory.addBeanPostProcessor(new BeanPostProcessor() {
7073
@Override
7174
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
@@ -82,16 +85,18 @@ public Object postProcessAfterInitialization(Object bean, String name) throws Be
8285
return bean;
8386
}
8487
});
88+
8589
this.factory.addBeanPostProcessor(new LifecycleBean.PostProcessor());
8690
this.factory.addBeanPostProcessor(new ProtectedLifecycleBean.PostProcessor());
87-
//this.factory.preInstantiateSingletons();
91+
// this.factory.preInstantiateSingletons();
8892
}
8993

9094
@Override
9195
protected BeanFactory getBeanFactory() {
9296
return factory;
9397
}
9498

99+
95100
@Test
96101
@Override
97102
public void count() {
@@ -104,19 +109,19 @@ public void beanCount() {
104109
}
105110

106111
@Test
107-
public void lifecycleMethods() throws Exception {
112+
public void lifecycleMethods() {
108113
LifecycleBean bean = (LifecycleBean) getBeanFactory().getBean("lifecycle");
109114
bean.businessMethod();
110115
}
111116

112117
@Test
113-
public void protectedLifecycleMethods() throws Exception {
118+
public void protectedLifecycleMethods() {
114119
ProtectedLifecycleBean bean = (ProtectedLifecycleBean) getBeanFactory().getBean("protectedLifecycle");
115120
bean.businessMethod();
116121
}
117122

118123
@Test
119-
public void descriptionButNoProperties() throws Exception {
124+
public void descriptionButNoProperties() {
120125
TestBean validEmpty = (TestBean) getBeanFactory().getBean("validEmptyWithDescription");
121126
assertEquals(0, validEmpty.getAge());
122127
}
@@ -125,7 +130,7 @@ public void descriptionButNoProperties() throws Exception {
125130
* Test that properties with name as well as id creating an alias up front.
126131
*/
127132
@Test
128-
public void autoAliasing() throws Exception {
133+
public void autoAliasing() {
129134
List beanNames = Arrays.asList(getListableBeanFactory().getBeanDefinitionNames());
130135

131136
TestBean tb1 = (TestBean) getBeanFactory().getBean("aliased");
@@ -224,7 +229,7 @@ public void prototypeReferences() {
224229
}
225230

226231
@Test
227-
public void beanPostProcessor() throws Exception {
232+
public void beanPostProcessor() {
228233
TestBean kerry = (TestBean) getBeanFactory().getBean("kerry");
229234
TestBean kathy = (TestBean) getBeanFactory().getBean("kathy");
230235
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");

spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private void startBeans(boolean autoStartupOnly) {
154154
/**
155155
* Start the specified bean as part of the given set of Lifecycle beans,
156156
* making sure that any beans that it depends on are started first.
157-
* @param lifecycleBeans Map with bean name as key and Lifecycle instance as value
157+
* @param lifecycleBeans a Map with bean name as key and Lifecycle instance as value
158158
* @param beanName the name of the bean to start
159159
*/
160160
private void doStart(Map<String, ? extends Lifecycle> lifecycleBeans, String beanName, boolean autoStartupOnly) {
@@ -167,7 +167,7 @@ private void doStart(Map<String, ? extends Lifecycle> lifecycleBeans, String bea
167167
if (!bean.isRunning() &&
168168
(!autoStartupOnly || !(bean instanceof SmartLifecycle) || ((SmartLifecycle) bean).isAutoStartup())) {
169169
if (logger.isDebugEnabled()) {
170-
logger.debug("Starting bean '" + beanName + "' of type [" + bean.getClass() + "]");
170+
logger.debug("Starting bean '" + beanName + "' of type [" + bean.getClass().getName() + "]");
171171
}
172172
try {
173173
bean.start();
@@ -207,7 +207,7 @@ private void stopBeans() {
207207
/**
208208
* Stop the specified bean as part of the given set of Lifecycle beans,
209209
* making sure that any beans that depends on it are stopped first.
210-
* @param lifecycleBeans Map with bean name as key and Lifecycle instance as value
210+
* @param lifecycleBeans a Map with bean name as key and Lifecycle instance as value
211211
* @param beanName the name of the bean to stop
212212
*/
213213
private void doStop(Map<String, ? extends Lifecycle> lifecycleBeans, final String beanName,
@@ -223,7 +223,8 @@ private void doStop(Map<String, ? extends Lifecycle> lifecycleBeans, final Strin
223223
if (bean.isRunning()) {
224224
if (bean instanceof SmartLifecycle) {
225225
if (logger.isDebugEnabled()) {
226-
logger.debug("Asking bean '" + beanName + "' of type [" + bean.getClass() + "] to stop");
226+
logger.debug("Asking bean '" + beanName + "' of type [" +
227+
bean.getClass().getName() + "] to stop");
227228
}
228229
countDownBeanNames.add(beanName);
229230
((SmartLifecycle) bean).stop(new Runnable() {
@@ -239,7 +240,8 @@ public void run() {
239240
}
240241
else {
241242
if (logger.isDebugEnabled()) {
242-
logger.debug("Stopping bean '" + beanName + "' of type [" + bean.getClass() + "]");
243+
logger.debug("Stopping bean '" + beanName + "' of type [" +
244+
bean.getClass().getName() + "]");
243245
}
244246
bean.stop();
245247
if (logger.isDebugEnabled()) {
@@ -248,7 +250,7 @@ public void run() {
248250
}
249251
}
250252
else if (bean instanceof SmartLifecycle) {
251-
// don't wait for beans that aren't running
253+
// Don't wait for beans that aren't running...
252254
latch.countDown();
253255
}
254256
}
@@ -307,8 +309,6 @@ protected int getPhase(Lifecycle bean) {
307309
*/
308310
private class LifecycleGroup {
309311

310-
private final List<LifecycleGroupMember> members = new ArrayList<LifecycleGroupMember>();
311-
312312
private final int phase;
313313

314314
private final long timeout;
@@ -317,20 +317,24 @@ private class LifecycleGroup {
317317

318318
private final boolean autoStartupOnly;
319319

320-
private volatile int smartMemberCount;
320+
private final List<LifecycleGroupMember> members = new ArrayList<LifecycleGroupMember>();
321+
322+
private int smartMemberCount;
323+
324+
public LifecycleGroup(
325+
int phase, long timeout, Map<String, ? extends Lifecycle> lifecycleBeans, boolean autoStartupOnly) {
321326

322-
public LifecycleGroup(int phase, long timeout, Map<String, ? extends Lifecycle> lifecycleBeans, boolean autoStartupOnly) {
323327
this.phase = phase;
324328
this.timeout = timeout;
325329
this.lifecycleBeans = lifecycleBeans;
326330
this.autoStartupOnly = autoStartupOnly;
327331
}
328332

329333
public void add(String name, Lifecycle bean) {
334+
this.members.add(new LifecycleGroupMember(name, bean));
330335
if (bean instanceof SmartLifecycle) {
331336
this.smartMemberCount++;
332337
}
333-
this.members.add(new LifecycleGroupMember(name, bean));
334338
}
335339

336340
public void start() {
@@ -363,7 +367,7 @@ public void stop() {
363367
doStop(this.lifecycleBeans, member.name, latch, countDownBeanNames);
364368
}
365369
else if (member.bean instanceof SmartLifecycle) {
366-
// already removed, must have been a dependent
370+
// Already removed: must have been a dependent bean from another phase
367371
latch.countDown();
368372
}
369373
}

spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@
4141
* <em>composed annotations</em> with attribute overrides.
4242
*
4343
* @author Mark Fisher
44+
* @author Juergen Hoeller
4445
* @author Dave Syer
4546
* @author Chris Beams
4647
* @since 3.0
@@ -55,10 +56,10 @@
5556
public @interface Scheduled {
5657

5758
/**
58-
* A cron-like expression, extending the usual UN*X definition to include
59-
* triggers on the second as well as minute, hour, day of month, month
60-
* and day of week. e.g. {@code "0 * * * * MON-FRI"} means once per minute on
61-
* weekdays (at the top of the minute - the 0th second).
59+
* A cron-like expression, extending the usual UN*X definition to include triggers
60+
* on the second as well as minute, hour, day of month, month and day of week.
61+
* <p>E.g. {@code "0 * * * * MON-FRI"} means once per minute on weekdays
62+
* (at the top of the minute - the 0th second).
6263
* @return an expression that can be parsed to a cron schedule
6364
* @see org.springframework.scheduling.support.CronSequenceGenerator
6465
*/

spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public class ScheduledAnnotationBeanPostProcessor
101101
SmartInitializingSingleton, ApplicationListener<ContextRefreshedEvent>, DisposableBean {
102102

103103
/**
104-
* The default name of the {@link TaskScheduler} bean to pick up: "taskScheduler".
104+
* The default name of the {@link TaskScheduler} bean to pick up: {@value}.
105105
* <p>Note that the initial lookup happens by type; this is just the fallback
106106
* in case of multiple scheduler beans found in the context.
107107
* @since 4.2

0 commit comments

Comments
 (0)