All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitlab.summercattle.addons.wechat.configure.WeChatAutoConfiguration Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2018 the original author or authors.
 *
 * Licensed 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.gitlab.summercattle.addons.wechat.configure;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.client.RestTemplate;

import com.gitlab.summercattle.addons.wechat.auth.service.impl.UserServiceImpl;
import com.gitlab.summercattle.addons.wechat.common.service.impl.WeChatServiceImpl;
import com.gitlab.summercattle.addons.wechat.constants.WeChatConstants;
import com.gitlab.summercattle.commons.utils.auxiliary.HttpUtils;
import com.gitlab.summercattle.commons.utils.spring.RestTemplateUtils;

/**
 * 微信服务自动配置
 * @author orange
 *
 */
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(WeChatConfigProperties.class)
@PropertySource("classpath:/com/gitlab/summercattle/addons/wechat/configure/wechat.properties")
@ComponentScan(basePackageClasses = { WeChatServiceImpl.class, UserServiceImpl.class })
@Import(WebSecurityConfig.class)
public class WeChatAutoConfiguration {

	@Bean(WeChatConstants.REST_TEMPLATE_UTILS_NAME)
	public RestTemplateUtils restTemplateUtils(@Qualifier(WeChatConstants.REST_TEMPLATE_NAME) RestTemplate restTemplate) {
		return new RestTemplateUtils(restTemplate);
	}

	@Bean(WeChatConstants.REST_TEMPLATE_NAME)
	@ConditionalOnMissingBean
	public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder, WeChatConfigProperties weChatConfigProperties) {
		return HttpUtils.getRestTemplate(restTemplateBuilder, weChatConfigProperties.getRestTemplateTimeout());
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy