From 89d42de0cec8ce5bf0553f3336627eaa9b1fbb46 Mon Sep 17 00:00:00 2001 From: Imteyaz Ahmad Date: Thu, 23 Apr 2015 10:39:01 +0530 Subject: [PATCH] Added Application.properties --- .../config/PersistenceContextConfig.java | 15 ++++++++++++++- .../java/com/imt/test/web/config/RootConfig.java | 2 ++ .../com/imt/test/web/config/WebMvcConfig.java | 9 +++++++++ .../src/main/resources/application.properties | 1 + TestWS-web/src/main/webapp/application.properties | 1 + 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 TestWS-web/src/main/resources/application.properties create mode 100644 TestWS-web/src/main/webapp/application.properties diff --git a/TestWS-persistence/src/main/java/com/imt/test/persistence/config/PersistenceContextConfig.java b/TestWS-persistence/src/main/java/com/imt/test/persistence/config/PersistenceContextConfig.java index 8ec32bf..24a588b 100644 --- a/TestWS-persistence/src/main/java/com/imt/test/persistence/config/PersistenceContextConfig.java +++ b/TestWS-persistence/src/main/java/com/imt/test/persistence/config/PersistenceContextConfig.java @@ -9,12 +9,14 @@ import javax.sql.DataSource; import org.apache.commons.dbcp2.BasicDataSource; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; 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.dao.annotation.PersistenceExceptionTranslationPostProcessor; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.JpaVendorAdapter; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; @@ -30,13 +32,18 @@ @ComponentScan(basePackages = { "com.imt.test" }) @EnableTransactionManagement @EnableJpaRepositories("com.imt.test.persistence.repo") +@PropertySource(value = { "application.properties" }) public class PersistenceContextConfig { + @Value("${db.url}") + private String dbUrl; + @Bean public DataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/imti"); + //dataSource.setUrl(dbUrl); dataSource.setUsername("root"); dataSource.setPassword("root"); return dataSource; @@ -77,4 +84,10 @@ Properties jpaProperties() { return prop; } + + @Bean + public PropertyPlaceholderConfigurer configurer() { + PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); + return configurer; + } } diff --git a/TestWS-web/src/main/java/com/imt/test/web/config/RootConfig.java b/TestWS-web/src/main/java/com/imt/test/web/config/RootConfig.java index 378eab8..d9e4fae 100644 --- a/TestWS-web/src/main/java/com/imt/test/web/config/RootConfig.java +++ b/TestWS-web/src/main/java/com/imt/test/web/config/RootConfig.java @@ -17,4 +17,6 @@ @ComponentScan(basePackages = { "com.imt.test" }, excludeFilters = { @Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class) }) public class RootConfig { + + } diff --git a/TestWS-web/src/main/java/com/imt/test/web/config/WebMvcConfig.java b/TestWS-web/src/main/java/com/imt/test/web/config/WebMvcConfig.java index ce2d1c0..3f7f3a4 100644 --- a/TestWS-web/src/main/java/com/imt/test/web/config/WebMvcConfig.java +++ b/TestWS-web/src/main/java/com/imt/test/web/config/WebMvcConfig.java @@ -3,9 +3,11 @@ */ package com.imt.test.web.config; +import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; 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.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @@ -20,6 +22,7 @@ @EnableWebMvc @Configuration @ComponentScan(basePackages = { "com.imt.test" }) +@PropertySource(value = { "application.properties" }) public class WebMvcConfig extends WebMvcConfigurerAdapter { @Bean @@ -44,4 +47,10 @@ public ControllerClassNameHandlerMapping controllerClassNameHandlerMapping() { } + @Bean + public PropertyPlaceholderConfigurer configurer() { + PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); + return configurer; + } + } diff --git a/TestWS-web/src/main/resources/application.properties b/TestWS-web/src/main/resources/application.properties new file mode 100644 index 0000000..1cd6187 --- /dev/null +++ b/TestWS-web/src/main/resources/application.properties @@ -0,0 +1 @@ +db.url=jdbc:mysql://localhost:3306/imti \ No newline at end of file diff --git a/TestWS-web/src/main/webapp/application.properties b/TestWS-web/src/main/webapp/application.properties new file mode 100644 index 0000000..1cd6187 --- /dev/null +++ b/TestWS-web/src/main/webapp/application.properties @@ -0,0 +1 @@ +db.url=jdbc:mysql://localhost:3306/imti \ No newline at end of file