У меня есть две базы данных, которые подключены к моему приложению, и, следовательно, у меня есть два таких разъема:
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef = DMP_SAP_ENTITY_MANAGER_FACTORY_BEAN_NAME)
class SapHanaConnectionConfiguration @Autowired constructor(private val environment: Environment) {
private val driverClassName by lazy { environment.getProperty(DMP_SAP_DRIVER_CLASS_NAME) }
private val jdbcString by lazy { environment.getProperty(DMP_SAP_JDBC_STRING) }
private val username by lazy { environment.getProperty(DMP_SAP_USERNAME) }
private val password by lazy { environment.getProperty(DMP_SAP_PASSWORD) }
@Bean(name = [DMP_SAP_DATA_SOURCE_BEAN_NAME])
fun dataSource(): DataSource = DataSourceBuilder.create()
.driverClassName(driverClassName)
.url(jdbcString)
.username(username)
.password(password)
.build()
@Bean(name = [DMP_SAP_ENTITY_MANAGER_FACTORY_BEAN_NAME])
fun entityManagerFactory(
builder: EntityManagerFactoryBuilder,
@Qualifier(DMP_SAP_DATA_SOURCE_BEAN_NAME) dataSource: DataSource
): LocalContainerEntityManagerFactoryBean = builder
.dataSource(dataSource)
.packages(DMP_SAP_MODEL_PACKAGE)
.persistenceUnit(DMP_SAP_PERSISTENCE_UNIT_NAME)
.build()
@Bean(name = [DMP_SAP_TRANSACTION_MANAGER_BEAN_NAME])
fun transactionManager(@Qualifier(DMP_SAP_ENTITY_MANAGER_FACTORY_BEAN_NAME) entityManagerFactory: EntityManagerFactory): PlatformTransactionManager =
JpaTransactionManager(entityManagerFactory)
}
Проблема в том, что этот конкретный разъем должен работать только в производственной среде, потому что он подключается кбаза данных с данными клиентов (которая находится во внутренней локальной сети и недоступна за пределами сети клиента).Прямо сейчас при разработке в моей локальной среде оба коннектора запускаются, и поэтому SapHanaConnection
выдает исключение, потому что не может установить соединение с данной БД.
2018-10-25 14:04:09.187 ERROR 13680 --- [n(14)-127.0.0.1] com.zaxxer.hikari.pool.HikariPool : HikariPool-2 - Exception during pool initialization.
com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: Cannot connect to jdbc:sap://CLIENTS_MACHINE/ [Unknown host CLIENTS_MACHINE [CLIENTS_MACHINE], -709].
at com.sap.db.jdbc.exceptions.SQLExceptionSapDB._newInstance(SQLExceptionSapDB.java:126)
at com.sap.db.jdbc.exceptions.SQLExceptionSapDB._newInstance(SQLExceptionSapDB.java:203)
at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.newInstance(SQLExceptionSapDB.java:50)
at com.sap.db.jdbc.DriverSapDB._connect(DriverSapDB.java:1404)
at com.sap.db.jdbc.DriverSapDB.connect(DriverSapDB.java:1102)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:117)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:123)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:365)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:194)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:460)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:534)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:151)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:324)
at org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator.getProduct(DataSourceHealthIndicator.java:122)
at org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator.doDataSourceHealthCheck(DataSourceHealthIndicator.java:109)
at org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator.doHealthCheck(DataSourceHealthIndicator.java:104)
at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:84)
at org.springframework.boot.actuate.health.CompositeHealthIndicator.health(CompositeHealthIndicator.java:68)
at org.springframework.boot.actuate.health.CompositeHealthIndicator.health(CompositeHealthIndicator.java:68)
at org.springframework.boot.actuate.health.HealthEndpoint.health(HealthEndpoint.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:223)
at org.springframework.boot.actuate.endpoint.invoke.reflect.ReflectiveOperationInvoker.invoke(ReflectiveOperationInvoker.java:76)
at org.springframework.boot.actuate.endpoint.annotation.AbstractDiscoveredOperation.invoke(AbstractDiscoveredOperation.java:61)
at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:104)
at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:93)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
at sun.reflect.GeneratedMethodAccessor193.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Я бы хотел как-то сказать, что этот разъем должен работать только при активном профиле, возможно ли это?
Я использую Spring Boot с Kotlin.