Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
QilongZhang committed Oct 15, 2018
1 parent d041d03 commit 505d0f6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ private void createDataSourceProxy(ConfigurableListableBeanFactory beanFactory,
values.add("appName", appName);
values.add("delegate", new RuntimeBeanReference(transformDatasourceBeanName(beanName)));
values.add("dbType", resolveDbTypeFromUrl(unwrapPropertyValue(originValues.get(jdbcUrl))));
values.add("database", resolveDatabaseFromUrl(unwrapPropertyValue(originValues.get(jdbcUrl))));
values.add("database",
resolveDatabaseFromUrl(unwrapPropertyValue(originValues.get(jdbcUrl))));
proxiedBeanDefinition.setPropertyValues(values);
beanDefinitionRegistry.registerBeanDefinition(beanName, proxiedBeanDefinition);
}
Expand All @@ -131,9 +132,10 @@ protected String unwrapPropertyValue(Object propertyValue) {
if (propertyValue instanceof TypedStringValue) {
return ((TypedStringValue) propertyValue).getValue();
} else if (propertyValue instanceof String) {
return (String)propertyValue;
return (String) propertyValue;
}
throw new IllegalArgumentException("The property value of jdbcUrl must be the type of String or TypedStringValue");
throw new IllegalArgumentException(
"The property value of jdbcUrl must be the type of String or TypedStringValue");
}

public static String transformDatasourceBeanName(String originName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/**
* Alipay.com Inc.
* Copyright (c) 2004-2018 All Rights Reserved.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.tracer.boot.base;

Expand All @@ -19,22 +31,29 @@
public class DatasourceBeanDefinitionRegistry implements BeanDefinitionRegistryPostProcessor {

@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
BeanDefinitionBuilder definitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(HikariDataSource.class);
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
throws BeansException {
BeanDefinitionBuilder definitionBuilder = BeanDefinitionBuilder
.genericBeanDefinition(HikariDataSource.class);
AbstractBeanDefinition beanDefinition = definitionBuilder.getRawBeanDefinition();
beanDefinition.setDestroyMethodName("close");
beanDefinition.setPrimary(false);

definitionBuilder.addPropertyValue("driverClassName", "org.h2.Driver");
definitionBuilder.addPropertyValue("jdbcUrl", "jdbc:mysql://1.1.1.1:3306/xxx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull");
definitionBuilder
.addPropertyValue(
"jdbcUrl",
"jdbc:mysql://1.1.1.1:3306/xxx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull");
definitionBuilder.addPropertyValue("username", "sofa");
definitionBuilder.addPropertyValue("password", "123456");

registry.registerBeanDefinition("manualDataSource", definitionBuilder.getRawBeanDefinition());
registry.registerBeanDefinition("manualDataSource",
definitionBuilder.getRawBeanDefinition());
}

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException {
// ignore
}
}

0 comments on commit 505d0f6

Please sign in to comment.