会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133308个问题

package com.bjsxt.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * 发送信息线程
 */
class ClientSend extends Thread{
    private Socket socket;
    ClientSend(Socket socket){
        this.socket = socket;
    }

    @Override
    public void run() {
        this.sendMsg();
    }
    /**
     * 发送消息
     */
    private void sendMsg(){
        Scanner scanner = null;
        PrintWriter pw = null;
        try {
            scanner  = new Scanner(System.in);
            pw = new PrintWriter(this.socket.getOutputStream());
            String str = scanner.nextLine();
            while (true){
                if ("exit".equals(str)){
                    break;
                }
                pw.println(str);
                pw.flush();
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (pw!=null){
                pw.close();
            }
            if (scanner!=null){
                scanner.close();
            }
        }

    }
}
/**
 * 接受消息线程
 */
class ClientReceive extends Thread{
    private Socket socket;
    ClientReceive(Socket socket){
        this.socket = socket;
    }
    @Override
    public void run() {
        this.receiveMsg();
    }
    /**
     * 接受消息
     */
    private void receiveMsg(){
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
            while (true){
                String clientStr = br.readLine();
                if ("exit".equals(clientStr)){
                    break;
                }
                System.out.println("客户端说:"+clientStr);
            }


        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (br!=null){
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
public class ChatSocketClient {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("127.0.0.1",8888);
            System.out.println("连接成功!");
            new ClientReceive(socket).start();
            new ClientSend(socket).start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

image.png

老师,为啥我这里死循环了,大家都用的where(true)了呀,而且我前面的双向通信和单向都用的了where(true)

和老师写的差不多,到点对点练习就死循环了

JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 24571楼

请问安装mysqlclient只是为了简化命令python manage.py吗?我在操作时,更改了DATABASES中的内容时就会提示:Did you install mysqlclient or MySQL-python?


执行安装mysqlclient命令(视频中pip3 install mysqlclient,为什么是pip3,我试了pip install mysqlclient,好像效果都一样,没能安装成功,提示的错误也一样,如下:)

(venv) D:\PycharmProjects\zhuce>pip3 install mysqlclient

Collecting mysqlclient

  Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post

1.tar.gz

Installing collected packages: mysqlclient

  Running setup.py install for mysqlclient ... error

    Complete output from command D:\PycharmProjects\zhuce\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\ThinkP

ad\\AppData\\Local\\Temp\\pip-install-a58bcz2e\\mysqlclient\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n',

 '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\ThinkPad\AppData\Local\Temp\pip-record-j4b8_u4b\install-record

.txt --single-version-externally-managed --compile --install-headers D:\PycharmProjects\zhuce\venv\include\site\python3.6\mysqlclient:

    C:\Users\ThinkPad\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py:261: UserWarning: Unknown distribution option: 'long_descr

iption_content_type'

      warnings.warn(msg)

    running install

    running build

    running build_py

    creating build

    creating build\lib.win32-3.6

    creating build\lib.win32-3.6\MySQLdb

    copying MySQLdb\__init__.py -> build\lib.win32-3.6\MySQLdb

    copying MySQLdb\_exceptions.py -> build\lib.win32-3.6\MySQLdb

    copying MySQLdb\compat.py -> build\lib.win32-3.6\MySQLdb

    copying MySQLdb\connections.py -> build\lib.win32-3.6\MySQLdb

    copying MySQLdb\converters.py -> build\lib.win32-3.6\MySQLdb

    copying MySQLdb\cursors.py -> build\lib.win32-3.6\MySQLdb

    copying MySQLdb\release.py -> build\lib.win32-3.6\MySQLdb

    copying MySQLdb\times.py -> build\lib.win32-3.6\MySQLdb

    creating build\lib.win32-3.6\MySQLdb\constants

    copying MySQLdb\constants\__init__.py -> build\lib.win32-3.6\MySQLdb\constants

    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.6\MySQLdb\constants

    copying MySQLdb\constants\CR.py -> build\lib.win32-3.6\MySQLdb\constants

    copying MySQLdb\constants\ER.py -> build\lib.win32-3.6\MySQLdb\constants

    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.6\MySQLdb\constants

    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.6\MySQLdb\constants

    running build_ext

    building 'MySQLdb._mysql' extension

    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-

build-tools


    ----------------------------------------

Command "D:\PycharmProjects\zhuce\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\ThinkPad\\AppData\\Local\\Temp

\\pip-install-a58bcz2e\\mysqlclient\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(co

mpile(code, __file__, 'exec'))" install --record C:\Users\ThinkPad\AppData\Local\Temp\pip-record-j4b8_u4b\install-record.txt --single-version-ex

ternally-managed --compile --install-headers D:\PycharmProjects\zhuce\venv\include\site\python3.6\mysqlclient" failed with error code 1 in C:\Us

ers\ThinkPad\AppData\Local\Temp\pip-install-a58bcz2e\mysqlclient\

You are using pip version 10.0.1, however version 19.1.1 is available.

You should consider upgrading via the 'python -m pip install --upgrade pip' command.


Python 全系列/第九阶段:Python_Django2 框架(隐藏)/Django模型层 24572楼
JAVA 全系列/第四阶段:数据库与AI协同技术实战/JDBC技术 24573楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 24575楼

1、老师您好,部署consumer时,运行tomcat7:run 报错如下。详细错误在附件里。老师帮忙给看下吧。百度好久没有答案。

完整错误.txt




严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed;
 nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.bjsxt.dubbo.service.AddUserDubboService com.bjsxt.service.impl.UserServiceImpl.addUserDubboService;
 nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addUserDubboService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException:
 Failed to check the status of the service com.bjsxt.dubbo.service.AddUserDubboService. No provider available for the service com.bjsxt.dubbo.service.AddUserDubboService from the url zookeeper://192.168.243.128:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=myconsumer1111&check=false&dubbo=2.5.4&generic=false&interface=com.bjsxt.dubbo.service.AddUserDubboService&methods=addUser&pid=792&revision=0.0.1-SNAPSHOT&side=consumer&timeout=300000&timestamp=1565435252238 to the consumer 192.168.243.1 use dubbo version 2.5.4
   
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.bjsxt.dubbo.service.AddUserDubboService com.bjsxt.service.impl.UserServiceImpl.addUserDubboService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addUserDubboService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.bjsxt.dubbo.service.AddUserDubboService. No provider available for the service com.bjsxt.dubbo.service.AddUserDubboService from the url zookeeper://192.168.243.128:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=myconsumer1111&check=false&dubbo=2.5.4&generic=false&interface=com.bjsxt.dubbo.service.AddUserDubboService&methods=addUser&pid=792&revision=0.0.1-SNAPSHOT&side=consumer&timeout=300000&timestamp=1565435252238 to the consumer 192.168.243.1 use dubbo version 2.5.4
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addUserDubboService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.bjsxt.dubbo.service.AddUserDubboService. No provider available for the service com.bjsxt.dubbo.service.AddUserDubboService from the url zookeeper://192.168.243.128:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=myconsumer1111&check=false&dubbo=2.5.4&generic=false&interface=com.bjsxt.dubbo.service.AddUserDubboService&methods=addUser&pid=792&revision=0.0.1-SNAPSHOT&side=consumer&timeout=300000&timestamp=1565435252238 to the consumer 192.168.243.1 use dubbo version 2.5.4
Caused by: java.lang.IllegalStateException: Failed to check the status of the service com.bjsxt.dubbo.service.AddUserDubboService. No provider available for the service com.bjsxt.dubbo.service.AddUserDubboService from the url zookeeper://192.168.243.128:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=myconsumer1111&check=false&dubbo=2.5.4&generic=false&interface=com.bjsxt.dubbo.service.AddUserDubboService&methods=addUser&pid=792&revision=0.0.1-SNAPSHOT&side=consumer&timeout=300000&timestamp=1565435252238 to the consumer 192.168.243.1 use dubbo version 2.5.4
   

JAVA 全系列/(旧的隐藏)第七阶段:JAVA 高级技术/Dubbo 24577楼
Python 全系列/第十五阶段:Python 爬虫开发/爬虫反反爬 24578楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 24584楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637