diff --git a/spring-all/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch b/spring-all/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch deleted file mode 100644 index 627021fb96..0000000000 --- a/spring-all/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/spring-all/.settings/org.eclipse.jdt.core.prefs b/spring-all/.settings/org.eclipse.jdt.core.prefs index 0924ed68cf..723e5b1245 100644 --- a/spring-all/.settings/org.eclipse.jdt.core.prefs +++ b/spring-all/.settings/org.eclipse.jdt.core.prefs @@ -6,7 +6,11 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore diff --git a/spring-all/pom.xml b/spring-all/pom.xml index e801ff8c54..7e93da8b64 100644 --- a/spring-all/pom.xml +++ b/spring-all/pom.xml @@ -84,7 +84,14 @@ - + + + org.springframework + spring-test + ${org.springframework.version} + test + + junit junit-dep diff --git a/spring-all/src/main/java/org/baeldung/core/ComponentUsingProperties.java b/spring-all/src/main/java/org/baeldung/core/ComponentUsingProperties.java index b3b44da3bd..7df4d8ead0 100644 --- a/spring-all/src/main/java/org/baeldung/core/ComponentUsingProperties.java +++ b/spring-all/src/main/java/org/baeldung/core/ComponentUsingProperties.java @@ -1,12 +1,30 @@ package org.baeldung.core; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @Component -public class ComponentUsingProperties { +public class ComponentUsingProperties implements InitializingBean { + + @Autowired + private Environment env; + + @Value("${key.something}") + private String injectedProperty; public ComponentUsingProperties() { super(); } + // + + @Override + public void afterPropertiesSet() throws Exception { + System.out.println("via @Value: " + injectedProperty); + System.out.println("via Environment: " + env.getProperty("key.something")); + } + } diff --git a/spring-all/src/main/java/org/baeldung/spring/config/PersistenceConfig.java b/spring-all/src/main/java/org/baeldung/spring/config/PersistenceConfig.java index 078d7e6f88..6a057fc0c7 100644 --- a/spring-all/src/main/java/org/baeldung/spring/config/PersistenceConfig.java +++ b/spring-all/src/main/java/org/baeldung/spring/config/PersistenceConfig.java @@ -7,7 +7,6 @@ import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; @@ -18,10 +17,10 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; import com.google.common.base.Preconditions; -@Configuration +// @Configuration @EnableTransactionManagement @PropertySource({ "classpath:persistence-mysql.properties" }) -@ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" }) +@ComponentScan({ "org.baeldung.persistence" }) public class PersistenceConfig { @Autowired diff --git a/spring-all/src/main/resources/configForProperties.xml b/spring-all/src/main/resources/configForProperties.xml index 9cd3282179..c3218dffa4 100644 --- a/spring-all/src/main/resources/configForProperties.xml +++ b/spring-all/src/main/resources/configForProperties.xml @@ -4,6 +4,6 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> - + \ No newline at end of file diff --git a/spring-all/src/main/resources/foo.properties b/spring-all/src/main/resources/foo.properties new file mode 100644 index 0000000000..7c47cd7880 --- /dev/null +++ b/spring-all/src/main/resources/foo.properties @@ -0,0 +1 @@ +key.something=val \ No newline at end of file diff --git a/spring-all/src/main/resources/persistence-mysql.properties b/spring-all/src/main/resources/persistence-mysql.properties deleted file mode 100644 index 8263b0d9ac..0000000000 --- a/spring-all/src/main/resources/persistence-mysql.properties +++ /dev/null @@ -1,10 +0,0 @@ -# jdbc.X -jdbc.driverClassName=com.mysql.jdbc.Driver -jdbc.url=jdbc:mysql://localhost:3306/spring_hibernate4_01?createDatabaseIfNotExist=true -jdbc.user=tutorialuser -jdbc.pass=tutorialmy5ql - -# hibernate.X -hibernate.dialect=org.hibernate.dialect.MySQL5Dialect -hibernate.show_sql=false -hibernate.hbm2ddl.auto=create-drop diff --git a/spring-all/src/test/java/org/baeldung/core/PropertiesViaXmlIntegrationTest.java b/spring-all/src/test/java/org/baeldung/core/PropertiesViaXmlIntegrationTest.java new file mode 100644 index 0000000000..5bfede4217 --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/core/PropertiesViaXmlIntegrationTest.java @@ -0,0 +1,19 @@ +package org.baeldung.core; + +import org.baeldung.spring.config.CoreConfig; +import org.junit.Test; +import org.junit.runner.RunWith; +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 = { CoreConfig.class }, loader = AnnotationConfigContextLoader.class) +public class PropertiesViaXmlIntegrationTest { + + @Test + public final void givenContextIsInitialized_thenNoException() { + // + } + +}