Initial classes
This commit is contained in:
parent
0d2137f19e
commit
f755fce0bb
|
@ -1,5 +1,5 @@
|
|||
package org.baeldung.profiles;
|
||||
|
||||
public interface DatasourceConfig {
|
||||
public void setup();
|
||||
void setup();
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package org.baeldung.startup;
|
||||
|
||||
public class OnStartupApplicationListenerExampleBean {
|
||||
}
|
|
@ -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() {
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue