Initial classes

This commit is contained in:
Grzegorz Piwowarek 2016-08-13 13:12:57 +02:00
parent 0d2137f19e
commit f755fce0bb
7 changed files with 85 additions and 1 deletions

View File

@ -1,5 +1,5 @@
package org.baeldung.profiles;
public interface DatasourceConfig {
public void setup();
void setup();
}

View File

@ -0,0 +1,12 @@
package org.baeldung.startup;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Scope;
@Scope(value = "prototype")
public class InitializingBeanExampleBean implements InitializingBean {
@Override
public void afterPropertiesSet() throws Exception {
}
}

View File

@ -0,0 +1,18 @@
package org.baeldung.startup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@Component
@Scope(value = "prototype")
public class LogicInConstructorExampleBean {
@Autowired
private Environment environment;
public LogicInConstructorExampleBean() {
environment.getActiveProfiles();
}
}

View File

@ -0,0 +1,4 @@
package org.baeldung.startup;
public class OnStartupApplicationListenerExampleBean {
}

View File

@ -0,0 +1,15 @@
package org.baeldung.startup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@Component
public class PostConstructExampleBean {
@Autowired
private Environment environment;
public PostConstructExampleBean() {
}
}

View File

@ -0,0 +1,10 @@
package org.baeldung.startup;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan("org.baeldung.startup")
public class SpringStartupConfig {
}

View File

@ -0,0 +1,25 @@
package org.baeldung.startup;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { SpringStartupConfig.class }, loader = AnnotationConfigContextLoader.class)
public class SpringStartupTest {
@Autowired
private ApplicationContext ctx;
@Test(expected = BeanCreationException.class)
public void whenInstantiating_shouldThrowNPE() throws Exception {
ctx.getBean(LogicInConstructorExampleBean.class);
}
}