This commit is contained in:
Sanders committed 2024-01-19 15:50:53 +03:00
1 parent d5430a231c
commit f539ebe443
3 files changed
+19 -7

No files matched your search

@@ -5,6 +5,8 @@ import org.springframework.context.ApplicationContext;
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.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@@ -14,7 +16,7 @@ import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
import javax.sql.DataSource;
import java.sql.DriverManager;
import java.util.Objects;
/**
* @author Neil Alishev
@@ -22,13 +24,15 @@ import java.sql.DriverManager;
@Configuration
@ComponentScan("org.example")
@EnableWebMvc
@PropertySource("classpath:database.properties")
public class SpringConfig implements WebMvcConfigurer {
private final ApplicationContext applicationContext;
private final Environment environment;
@Autowired
public SpringConfig(ApplicationContext applicationContext) {
public SpringConfig(ApplicationContext applicationContext, Environment environment) {
this.applicationContext = applicationContext;
this.environment = environment;
}
@Bean
@@ -58,10 +62,10 @@ public class SpringConfig implements WebMvcConfigurer {
@Bean
public DataSource dataSource(){
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://192.168.0.10:5432/java");
dataSource.setUsername("sanders");
dataSource.setPassword("sanders");
dataSource.setDriverClassName(Objects.requireNonNull(environment.getProperty("driver")));
dataSource.setUrl(Objects.requireNonNull(environment.getProperty("url")));
dataSource.setUsername(Objects.requireNonNull(environment.getProperty("username")));
dataSource.setPassword(Objects.requireNonNull(environment.getProperty("password")));
return dataSource;
}
+4
View File
@@ -0,0 +1,4 @@
driver=org.postgresql.Driver
url=jdbc:postgresql://192.168.0.10:5432/java
username=sanders
password=sanders
@@ -0,0 +1,4 @@
driver=
url=
username=
password=