Add AllStrategies combined example

This commit is contained in:
Grzegorz Piwowarek 2016-08-15 17:44:19 +02:00
parent d27db567c1
commit 208fcaa915
4 changed files with 44 additions and 4 deletions

View File

@ -0,0 +1,33 @@
package org.baeldung.startup;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
@Scope(value = "prototype")
public class AllStrategiesExampleBean implements InitializingBean {
private static final Logger LOG = Logger.getLogger(AllStrategiesExampleBean.class);
public AllStrategiesExampleBean() {
LOG.info("Constructor");
}
@Override
public void afterPropertiesSet() throws Exception {
LOG.info("InitializingBean");
}
@PostConstruct
public void postConstruct() {
LOG.info("PostConstruct");
}
public void init() {
LOG.info("init-method");
}
}

View File

@ -2,14 +2,10 @@ package org.baeldung.startup;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.util.Arrays;
@Component
@Scope(value = "prototype")
public class InitMethodExampleBean {
private static final Logger LOG = Logger.getLogger(InitMethodExampleBean.class);

View File

@ -5,6 +5,12 @@
<bean id="initMethodExampleBean"
class="org.baeldung.startup.InitMethodExampleBean"
scope="prototype"
init-method="init">
</bean>
<bean id="allStrategiesExampleBean"
class="org.baeldung.startup.AllStrategiesExampleBean"
init-method="init">
</bean>
</beans>

View File

@ -18,4 +18,9 @@ public class SpringStartupXMLConfigTest {
public void whenPostConstruct_shouldLogEnv() throws Exception {
ctx.getBean(InitMethodExampleBean.class);
}
@Test
public void whenAllStrategies_shouldLogOrder() throws Exception {
ctx.getBean(AllStrategiesExampleBean.class);
}
}