Browse Source

datasource 不可注入bug修复

demon 8 years ago
parent
commit
15838a88fe

+ 1 - 5
hos-arbiter/src/main/java/com/yihu/hos/arbiter/configuration/ArbiterServerConfiguration.java

@ -19,14 +19,10 @@ public class ArbiterServerConfiguration {
    private String terminalUrl;
    @Value("${arbiter.tenant.name}")
    private String tenant;
    @Value("${arbiter.mycat.name}")
    private String mycatName;
    private ZbusBroker zbusBroker;
    public String getMycatName() {
        return mycatName;
    }
    public String getCentralUrl() {
        return centralUrl;

+ 3 - 1
hos-arbiter/src/main/java/com/yihu/hos/arbiter/services/ProxyService.java

@ -7,6 +7,7 @@ import com.yihu.hos.web.framework.constant.EndPointConstant;
import com.yihu.hos.web.framework.constant.MycatConstant;
import com.yihu.hos.web.framework.constant.SSHConstant;
import com.yihu.hos.web.framework.constant.ServiceFlowConstant;
import com.yihu.hos.web.framework.util.HostUtil;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.springframework.beans.factory.annotation.Autowired;
@ -106,7 +107,8 @@ public class ProxyService {
            }
            try {
                consumer = new Consumer(zbusBroker, MycatConstant.ZBUS_MQ + "@" + configuration.getMycatName());
                String ip = HostUtil.getAddress();
                consumer = new Consumer(zbusBroker, MycatConstant.ZBUS_MQ + "@" + configuration.getTenant()+ip);
                consumer.start(this::handle);
            } catch (IOException e) {
                e.printStackTrace();

+ 1 - 2
hos-arbiter/src/main/resources/application.yml

@ -29,8 +29,7 @@ arbiter:
    url: 192.168.131.119:15555
  tenant:
    name: jkzl
  mycat:
    name: mycat192.168.75.128    ##mycat 服务器标识,规则:“mycat"+ 本机IP
---
spring:
  profiles: test

+ 2 - 2
src/main/java/com/yihu/hos/config/BeanConfig.java

@ -1,7 +1,6 @@
package com.yihu.hos.config;
import com.yihu.hos.interceptor.AuditInterceptor;
import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
@ -21,6 +20,7 @@ import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.zbus.broker.ZbusBroker;
import javax.sql.DataSource;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Locale;
@ -38,7 +38,7 @@ import java.util.Properties;
public class BeanConfig {
    @Autowired
    BasicDataSource dataSource;
    private DataSource dataSource;
    @Value("${hos.zbus.url}")
    private String zbusUrl;

+ 5 - 5
src/main/java/com/yihu/hos/services/ServiceMycatEventService.java

@ -34,12 +34,12 @@ public class ServiceMycatEventService {
        this.zbusBroker = zbusBroker;
    }
    public void executeMycatConfig(ServiceMycat servviceMycat, String tenant) {
        this.sendMsg(MycatConstant.EXECUTE_MYCAT, servviceMycat, tenant);
    public void executeMycatConfig(ServiceMycat servviceMycat, String tenantAndHost) {
        this.sendMsg(MycatConstant.EXECUTE_MYCAT, servviceMycat, tenantAndHost);
    }
    private void sendMsg(String event, ServiceMycat servviceMycat, String tenant) {
    private void sendMsg(String event, ServiceMycat servviceMycat, String tenantAndHost) {
        if (zbusBroker == null) {
            logger.error("zbusBroker is null.");
            return;
@ -48,11 +48,11 @@ public class ServiceMycatEventService {
        try {
            String msg = objectMapper.writeValueAsString(servviceMycat);
            Producer producer = new Producer(zbusBroker, MycatConstant.ZBUS_MQ + "@" + tenant);
            Producer producer = new Producer(zbusBroker, MycatConstant.ZBUS_MQ + "@" + tenantAndHost);
            producer.createMQ();    //确定为创建消息队列需要显示调用
            Message message = new Message();
            message.setHead("event", event);
            message.setHead("tenant", tenant);
            message.setHead("tenant", tenantAndHost);
            message.setMethod("POST");
            message.setBody(msg);
            producer.sendSync(message);

+ 1 - 1
src/main/java/com/yihu/hos/tenant/service/TenantService.java

@ -98,7 +98,7 @@ public class TenantService {
                serrviceMycat.setTenant(MycatConstant.ZBUS_MQ+db.getHost());
                serrviceMycat.setLoginName(obj.getLoginName());
                serrviceMycat.setPassword(obj.getPassword());
                serviceMycatEventService.executeMycatConfig(serrviceMycat, MycatConstant.ZBUS_MQ+dbInfo.getHost());
                serviceMycatEventService.executeMycatConfig(serrviceMycat, MycatConstant.ZBUS_MQ + obj.getSchema() + dbInfo.getHost());
                tenantDao.saveEntity(obj);
                return Result.success("保存成功");
            }else {