MinnorUpdate

Перенес настройки базы и hibernate в properties
This commit is contained in:
Mark Struchkov 2018-12-22 01:38:29 +03:00
parent 6fa2baac7e
commit 8be8c6f1fa
2 changed files with 21 additions and 14 deletions

View File

@ -1,9 +1,11 @@
package org.sadtech.vkbot.config; package org.sadtech.vkbot.config;
import org.hibernate.jpa.HibernatePersistenceProvider; import org.hibernate.jpa.HibernatePersistenceProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.JpaTransactionManager;
@ -17,23 +19,26 @@ import java.util.Properties;
@EnableTransactionManagement @EnableTransactionManagement
@ComponentScan("org.sadtech.vkbot") @ComponentScan("org.sadtech.vkbot")
@EnableJpaRepositories("org.sadtech.vkbot.repo") @EnableJpaRepositories("org.sadtech.vkbot.repo")
@PropertySource("classpath:app.properties")
public class DataConfig { public class DataConfig {
private static final String PROPERTY_NAME_DATABASE_DRIVER = "com.mysql.jdbc.Driver"; @Value("${db.driver}")
private static final String PROPERTY_NAME_DATABASE_URL = "jdbc:mysql://localhost:3306/testbd"+ private String PROPERTY_NAME_DATABASE_DRIVER;
"?verifyServerCertificate=false"+ @Value("${db.url}")
"&useSSL=false"+ private String PROPERTY_NAME_DATABASE_URL;
"&requireSSL=false"+ @Value("${db.username}")
"&useLegacyDatetimeCode=false"+ private String PROPERTY_NAME_DATABASE_USERNAME;
"&amp"+ @Value("${db.password}")
"&serverTimezone=UTC"; private String PROPERTY_NAME_DATABASE_PASSWORD;
private static final String PROPERTY_NAME_DATABASE_USERNAME = "root";
private static final String PROPERTY_NAME_DATABASE_PASSWORD = "121314185398MAmaPApa";
private static final String PROPERTY_NAME_HIBERNATE_DIALECT = "org.hibernate.dialect.MySQL5Dialect"; @Value("${db.hibernate.dialect}")
private static final String PROPERTY_NAME_HIBERNATE_SHOW_SQL = "true"; private String PROPERTY_NAME_HIBERNATE_DIALECT;
private static final String PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN = "org.sadtech.vkbot"; @Value("${db.hibernate.show_sql}")
private static final String PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO = "create-drop"; private String PROPERTY_NAME_HIBERNATE_SHOW_SQL;
@Value("${db.entitymanager.packages.to.scan}")
private String PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN;
@Value("${db.hibernate.hbm2ddl.auto}")
private String PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO;
@Bean @Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

View File

@ -4,8 +4,10 @@ import org.sadtech.vkbot.dao.User;
import org.sadtech.vkbot.repo.UserRepository; import org.sadtech.vkbot.repo.UserRepository;
import org.sadtech.vkbot.service.UserService; import org.sadtech.vkbot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService { public class UserServiceImpl implements UserService {
@Autowired @Autowired