Skip to content

Commit ebc8e51

Browse files
committed
Merge pull request #7 from ahmadimt/imti
Added application.properties
2 parents 1e83607 + 89d42de commit ebc8e51

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

TestWS-persistence/src/main/java/com/imt/test/persistence/config/PersistenceContextConfig.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
import javax.sql.DataSource;
1010

1111
import org.apache.commons.dbcp2.BasicDataSource;
12+
import org.springframework.beans.factory.annotation.Value;
13+
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
1214
import org.springframework.context.annotation.Bean;
1315
import org.springframework.context.annotation.ComponentScan;
1416
import org.springframework.context.annotation.Configuration;
17+
import org.springframework.context.annotation.PropertySource;
1518
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
1619
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
17-
import org.springframework.jdbc.datasource.DriverManagerDataSource;
1820
import org.springframework.orm.jpa.JpaTransactionManager;
1921
import org.springframework.orm.jpa.JpaVendorAdapter;
2022
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
@@ -30,13 +32,18 @@
3032
@ComponentScan(basePackages = { "com.imt.test" })
3133
@EnableTransactionManagement
3234
@EnableJpaRepositories("com.imt.test.persistence.repo")
35+
@PropertySource(value = { "application.properties" })
3336
public class PersistenceContextConfig {
3437

38+
@Value("${db.url}")
39+
private String dbUrl;
40+
3541
@Bean
3642
public DataSource dataSource() {
3743
BasicDataSource dataSource = new BasicDataSource();
3844
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
3945
dataSource.setUrl("jdbc:mysql://localhost:3306/imti");
46+
//dataSource.setUrl(dbUrl);
4047
dataSource.setUsername("root");
4148
dataSource.setPassword("root");
4249
return dataSource;
@@ -77,4 +84,10 @@ Properties jpaProperties() {
7784
return prop;
7885

7986
}
87+
88+
@Bean
89+
public PropertyPlaceholderConfigurer configurer() {
90+
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
91+
return configurer;
92+
}
8093
}

TestWS-web/src/main/java/com/imt/test/web/config/RootConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
@ComponentScan(basePackages = { "com.imt.test" }, excludeFilters = { @Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class) })
1818
public class RootConfig {
1919

20+
21+
2022
}

TestWS-web/src/main/java/com/imt/test/web/config/WebMvcConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
*/
44
package com.imt.test.web.config;
55

6+
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
67
import org.springframework.context.annotation.Bean;
78
import org.springframework.context.annotation.ComponentScan;
89
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.context.annotation.PropertySource;
911
import org.springframework.web.servlet.ViewResolver;
1012
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
1113
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@@ -20,6 +22,7 @@
2022
@EnableWebMvc
2123
@Configuration
2224
@ComponentScan(basePackages = { "com.imt.test" })
25+
@PropertySource(value = { "application.properties" })
2326
public class WebMvcConfig extends WebMvcConfigurerAdapter {
2427

2528
@Bean
@@ -44,4 +47,10 @@ public ControllerClassNameHandlerMapping controllerClassNameHandlerMapping() {
4447

4548
}
4649

50+
@Bean
51+
public PropertyPlaceholderConfigurer configurer() {
52+
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
53+
return configurer;
54+
}
55+
4756
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
db.url=jdbc:mysql://localhost:3306/imti
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
db.url=jdbc:mysql://localhost:3306/imti

0 commit comments

Comments
 (0)