diff --git a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/datasource/processor/DataSourceBeanFactoryPostProcessor.java b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/datasource/processor/DataSourceBeanFactoryPostProcessor.java index 6143d8bb..649c0261 100644 --- a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/datasource/processor/DataSourceBeanFactoryPostProcessor.java +++ b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/datasource/processor/DataSourceBeanFactoryPostProcessor.java @@ -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); } @@ -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) { diff --git a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/base/DatasourceBeanDefinitionRegistry.java b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/base/DatasourceBeanDefinitionRegistry.java index f46b5074..35d7d002 100644 --- a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/base/DatasourceBeanDefinitionRegistry.java +++ b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/base/DatasourceBeanDefinitionRegistry.java @@ -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; @@ -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 } } \ No newline at end of file