Category Archives: JAVA

[Solved] Web server failed to start. Port 8080 was already in use.

Problem Description:

Description:

Web server failed to start. Port 8080 was already in use.

Action:

Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port.

Method 1: turn off the process occupying port 8080

    1. 1. keyboard input (Win + R), then enter “cmd” in the run dialog box, enter the command window
  1. 2. enter netstat -ano|findstr “8080”, and press Enter, as shown in the following screenshot:

3. Then enter tasklist|findstr “3516” and press enter to get the process occupying port 8080

4. Open the “task manager”, locate the change process, and then end the process. The occupation of port 8080 is cancelled

Or close with the command: taskkill -PID 3516 -F

Method 2: modify the configuration file and use other available ports

We can modify the port number in application.yml configuration file, as shown below:

View port, process and end process on Linux system

  a,Check port occupancy
    netstat -nap|grep 8080
  b,View port occupied processes
     ps -aux |grep 27672
   c,End a process
    kill -9 pid

[Solved] Project Startup Error: Redis health check failed: Unable to connect to localhost6379

Error reporting details

Analysis and solution

There is no connection of redis in my project, so it’s strange to report an error. Combined with the sentence redis health check failed, guess which thing introduced redis, and then do the health check of redis.

The solution is as follows: configurate as the following in application.yml

# Disable Actuator monitoring of Redis connections
management:
  health:
    redis:
      enabled: false

[Solved] ES Error: Elasticsearch health check failed

Original error report:

2020-11-30 18:39:08.019  WARN 17664 --- [-192.168.113.22] s.b.a.e.ElasticsearchRestHealthIndicator : Elasticsearch health check failed

java.net.ConnectException: Timeout connecting to [localhost/127.0.0.1:9200]
	at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:943) ~[elasticsearch-rest-client-6.4.3.jar:6.4.3]
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:227) ~[elasticsearch-rest-client-6.4.3.jar:6.4.3]
	at org.springframework.boot.actuate.elasticsearch.ElasticsearchRestHealthIndicator.doHealthCheck(ElasticsearchRestHealthIndicator.java:60) ~[spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:82) ~[spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.health.CompositeHealthIndicator.health(CompositeHealthIndicator.java:95) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.health.HealthEndpoint.health(HealthEndpoint.java:50) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
	at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282) [spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.boot.actuate.endpoint.invoke.reflect.ReflectiveOperationInvoker.invoke(ReflectiveOperationInvoker.java:76) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.endpoint.annotation.AbstractDiscoveredOperation.invoke(AbstractDiscoveredOperation.java:60) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:121) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:96) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [na:1.8.0_161]
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) [na:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:361) [na:1.8.0_161]
	at sun.rmi.transport.Transport$1.run(Transport.java:200) [na:1.8.0_161]
	at sun.rmi.transport.Transport$1.run(Transport.java:197) [na:1.8.0_161]
	at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_161]
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196) [na:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) [na:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) [na:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) [na:1.8.0_161]
	at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) [na:1.8.0_161]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_161]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_161]
	at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_161]
Caused by: java.net.ConnectException: Timeout connecting to [localhost/127.0.0.1:9200]
	at org.apache.http.nio.pool.RouteSpecificPool.timeout(RouteSpecificPool.java:169) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.nio.pool.AbstractNIOConnPool.requestTimeout(AbstractNIOConnPool.java:628) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.nio.pool.AbstractNIOConnPool$InternalSessionRequestCallback.timeout(AbstractNIOConnPool.java:894) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.reactor.SessionRequestImpl.timeout(SessionRequestImpl.java:183) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processTimeouts(DefaultConnectingIOReactor.java:210) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:155) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221) ~[httpasyncclient-4.1.4.jar:4.1.4]
	at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64) ~[httpasyncclient-4.1.4.jar:4.1.4]
	... 1 common frames omitted

Solution: add the following configuration to solve the problem successfully

  data:
    elasticsearch:
      repositories:
        enabled: true
      cluster-nodes: 192.168.136.137:9300
      cluster-name: docker-cluster
  #      Add the following configuration to pass the health check
  elasticsearch:
    rest:
      uris: ["http://192.168.136.137:9200"]

Springboot Integrate Swagger2 Error: Failed to start bean ‘documentationPluginsBootstrapper‘;

The springboot integration swagger2 reported an error. The attempt to reduce the springboot version is invalid

Solution: Configuration in application.properties:

spring.mvc.pathmatch.matching-strategy=ant_path_matcher

Because the path matching used by Springfox is based on AntPathMatcher, while Spring Boot 2.6.X uses PathPatternMatcher.

[Solved] Error:java: Compilation failed: internal java compiler error

Error phenomenon

When using idea to import a new project or upgrade idea or create a new project, the following exception message will appear:

Error:java: Compilation failed: internal java compiler error 

Cause of error

This error is mainly caused by the JDK version. There are two reasons: the compiled version does not match, and the current project JDK version does not support.

View the JDK of the project

File -> Project Structure-> Project Settings -> Project or use the shortcut Ctrl+Alt+shift+S to open the JDK configuration of the project:

Check whether these two points are consistent with the target JDK.

View the JDK of the project

Click modules in the figure above to view the corresponding JDK version:

View java compiler version

When importing Java projects, the probability of this problem is high.

To solve this problem, reopening or modifying the contents of the POM file (Maven project) is likely to cause the JDK version to change back to 1.5. If it is a maven project, you can specify JDK related information in the POM file:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

[Solved] Heroku Error: Web process failed to bind to $PORT within 60 seconds of launch

Error description

If the set port number is less than 1000, an error will be reported, and there is no permission

2022-03-29T10:23:16.651636+00:00 heroku[web.1]: State changed from crashed to starting
2022-03-29T10:23:28.994173+00:00 heroku[web.1]: Starting process with command `python /code/server3.py`
2022-03-29T10:23:30.091143+00:00 app[web.1]: Traceback (most recent call last):
2022-03-29T10:23:30.091204+00:00 app[web.1]: File "/code/server3.py", line 247, in <module>
2022-03-29T10:23:30.091205+00:00 app[web.1]: serverSocket.bind(("127.0.0.1", serverPort))
2022-03-29T10:23:30.091208+00:00 app[web.1]: PermissionError: [Errno 13] Permission denied
2022-03-29T10:23:30.234919+00:00 heroku[web.1]: Process exited with status 1
2022-03-29T10:23:30.279569+00:00 heroku[web.1]: State changed from starting to crashed

If you set the port number to 8080, you will not be connected within 60 seconds

2022-03-29T10:53:34.400924+00:00 heroku[web.1]: State changed from crashed to starting
2022-03-29T10:53:49.432473+00:00 heroku[web.1]: Starting process with command `python /code/server3.py`
2022-03-29T10:53:33.432308+00:00 app[api]: Release v9 created by user ***@icloud.com
2022-03-29T10:53:33.432308+00:00 app[api]: Deployed web (350d1bd5740a) by user ***@icloud.com
2022-03-29T10:54:49.500818+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2022-03-29T10:54:49.587777+00:00 heroku[web.1]: Stopping process with SIGKILL
2022-03-29T10:54:49.800462+00:00 heroku[web.1]: Process exited with status 137

If the port number in the environment variable is referenced dynamically, the acquisition fails

2022-03-29T11:12:03.984493+00:00 heroku[web.1]: State changed from crashed to starting
2022-03-29T11:12:19.984320+00:00 heroku[web.1]: Starting process with command `python /code/server3.py`
2022-03-29T11:12:21.706887+00:00 heroku[web.1]: Process exited with status 1
2022-03-29T11:12:21.536737+00:00 app[web.1]: Traceback (most recent call last):
2022-03-29T11:12:21.536756+00:00 app[web.1]: File "/code/server3.py", line 248, in <module>
2022-03-29T11:12:21.536757+00:00 app[web.1]: serverSocket.bind(("0.0.0.0", serverPort))
2022-03-29T11:12:21.536757+00:00 app[web.1]: TypeError: an integer is required (got type NoneType)
2022-03-29T11:12:21.769096+00:00 heroku[web.1]: State changed from starting to crashed

No matter the local address is not written,
ServerSocket Bind ((“”, serverport))
or 127.0.0.1
ServerSocket Bind ((“127.0.0.1”, serverport))
or write 0.0.0
ServerSocket Bind ((“0.0.0.0”, serverport))
doesn’t work

 

Solution (Python Project):

Dynamic binding port number is required

To write this in dockerfile, pass in $post

#Base image based on
FROM python:3.4

#code added to code folder
ADD . /pythonProject /code

# Set the code folder to be the working directory
WORKDIR /code

# Install support
#RUN pip install -r requirements.txt

CMD python /code/server3.py $PORT

Python file writing format,  obtain through parameters in server.py

serverPort = int(sys.argv[1])

The complete structure is as follows

if __name__ == '__main__':
    serverSocket = socket(AF_INET, SOCK_STREAM)
    serverPort = int(sys.argv[1])
    serverSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
    serverSocket.bind(("", serverPort))

    serverSocket.listen(5)
    print('The server is running')
    # Main web server loop. It simply accepts TCP connections, and get the request processed in seperate threads.
    while True:
        # Set up a new connection from the client
        connectionSocket, addr = serverSocket.accept()
        # Clients timeout after 60 seconds of inactivity and must reconnect.
        connectionSocket.settimeout(600)
        # start new thread to handle incoming request
        _thread.start_new_thread(process, (connectionSocket,))

Solution (Nodejs Project):

// production
config.port = process.env.PORT

app.listen(config.port, () => {
  logger.info('Listening on port %d', config.port);
});

or

.listen(process.env.PORT || 5000)

or

production: {
    server: {
        host: '0.0.0.0',
        port: process.env.PORT
    }
}

Request processing failed; nested exception is java.lang.NullPointerException or UnsatisfiedDependencyE

1. Null pointer exception:

Request processing failed; nested exception is java.lang.NullPointerException

java.lang.NullPointerException
com.atguigu.mvc.controller.NodesController.getFilesAndSendId(NodesController.java:61)


See the exception address and check the control layer

Control level, line 61:

List<FilePath> files = fileService.getFiles();

current

@RequestMapping(value = "/getFilesAndSendId/{sensor_id}",method = RequestMethod.GET)

Parameter sensor_id is passed;

Solution to null pointer:
Original:

private FileService fileService;

Change to: add @Autowired annotation

 @Autowired
    private FileService fileService;

If there is any other error when you run the codes:

Servlet.init() of Servlet[DispatcherServlet] raises an exception.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘nodesController’: Unsatisfied dependency expressed through field ‘fileService’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.atguigu.mvc.service.FileService’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


Solution:
Check if the @Service annotation is added to the implementation class here

[Solved] Docker Start Error: System.InvalidOperationException Failed to set version to docker-desktop exit code

Project scenario:

Docker 3.2.2
win10 Home Edition

Problem Description:

The docker opens error: System.InvalidOperationException: Failed to set version to docker-desktop: exit code: -1
detailed error report:

System.InvalidOperationException:
Failed to set version to docker-desktop: exit code: -1
 stdout: ?S??v?[a?{|?W
N/ec??v?dO0
stderr: 
   在 Docker.ApiServices.WSL2.WslShortLivedCommandResult.LogAndThrowIfUnexpectedExitCode(String prefix, ILogger log, Int32 expectedExitCode) 位置 C:workspacesPR-15387srcgithub.comdockerpinatawinsrcDocker.ApiServicesWSL2WslCommand.cs:Line 146
   在 Docker.Engines.WSL2.WSL2Provisioning.<ProvisionAsync>d__8.MoveNext() 位置 C:workspacesPR-15387srcgithub.comdockerpinatawinsrcDocker.DesktopEnginesWSL2WSL2Provisioning.cs:Line 82
--- The end of the stack trace in the previous location where the exception was raised ---
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 Docker.Engines.WSL2.LinuxWSL2Engine.<DoStartAsync>d__26.MoveNext() 位置 C:workspacesPR-15387srcgithub.comdockerpinatawinsrcDocker.DesktopEnginesWSL2LinuxWSL2Engine.cs:Line 104
--- The end of the stack trace in the previous location where the exception was raised ---
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 Docker.ApiServices.StateMachines.TaskExtensions.<WrapAsyncInCancellationException>d__0.MoveNext() 位置 C:workspacesPR-15387srcgithub.comdockerpinatawinsrcDocker.ApiServicesStateMachinesTaskExtensions.cs:Line 29
--- The end of the stack trace in the previous location where the exception was raised ---
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 Docker.ApiServices.StateMachines.StartTransition.<DoRunAsync>d__5.MoveNext() 位置 C:workspacesPR-15387srcgithub.comdockerpinatawinsrcDocker.ApiServicesStateMachinesStartTransition.cs:Line 67
--- The end of the stack trace in the previous location where the exception was raised ---
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 Docker.ApiServices.StateMachines.StartTransition.<DoRunAsync>d__5.MoveNext() 位置 C:workspacesPR-15387srcgithub.comdockerpinatawinsrcDocker.ApiServicesStateMachinesStartTransition.cs:Line 92

Screenshot:

 

Solution:

Execute under cmd/shell

netsh winsock reset

Then restart docker

[Solved] hadoop Error: 9000 failed on connection exception java.net.ConnectException Denied to Access

To view the files on haddop, enter:

hadoop fs -ls /

The following occurred:

ls: Call From yx/127.0.1.1 to 0.0.0.0:9000 failed on connection exception: 
java.net.ConnectException: Denied to Access 
For more details see:  http://wiki.apache.org/hadoop/ConnectionRefused

Display 9000 port access denied
from the configuration file, you can know that Hadoop needs to access the machine through 9000 port, but now 9000 port access is denied
Input:

telnet localhost 9000

Display:

Trying 127.0.0.1…
telnet: Unable to connect to remote host: Connection refused

Input:

nmap -p 9000 localhost

Display:

Starting Nmap 7.80 ( https://nmap.org ) at 2020-04-25 14:57 CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000051s latency).
PORT STATE SERVICE
9000/tcp closed cslistener
Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds

 

Use the command:

 lsof -i :9000

See which app is using the port. If the result is empty (return value 1), it is not opened
the above is just to check the status and will not change anything.

Because hadoop connects to the local port in core-site.xml
Open $HADOOP_HOME/etc/hadoop/core-site.xml

<configuration>
<property>
    <name>hadoop.tmp.dir</name>
    <value>/data/tmp/hadoop/tmp</value>
</property>
<property>
    <name>fs.defaultFS</name>
    <value>hdfs://0.0.0.0:9000</value>
</property>
</configuration>

It is found that I have not configured the port number, which is modified to:
hdfs://localhost:9000
It still not work.
I tried many methods, and finally found that the most commonly used method on the Internet is to use this method, which is really OK:

cd $HADOOP_HOME/bin
hdfs namenode -format

But I still couldn’t run it. I tried many times and all the results were the same. Later, then I found an error:

WARN common.Util: Path /data/tmp/hadoop/hdfs/name should be specified as a URI in configuration files. Please update hdfs configuration.

This is due to the non-standard path. The file describing the path is in:

$HADOOP_HOMW/etc/hadoop/hdfs-site.xml

Place in the file:

 <property>  
     <name>dfs.datanode.data.dir</name>  
     <value>/data/tmp/hadoop/hdfs/data</value>  
 </property>

Amend to read:

  <property>  
     <name>dfs.datanode.data.dir</name>  
     <value>file:///data/tmp/hadoop/hdfs/data</value>  
 </property>

The warning disappears
but this does not play a decisive role. My reason is that the security mode is turned on. Just turn off the security mode

cd $HADOOP_HOME/bin
hadoop dfsadmin -safemode leave

Users can

hadoop dfsadmin -safemode value

Operation security mode
value value:
enter: enter security mode
leave: force to leave security mode
get: return to security mode status
wait: until the end of security mode
now:

root@yx:/apps/hadoop/bin# hadoop fs -ls /
20/04/25 19:24:24 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Found 1 items
drwxr-xr-x   - root supergroup          0 2020-04-25 17:13 /test

[Solved] Docker Startup Error: OCI runtime create failed container_linux.go380 starting container process

Docker startup error

response from daemon: OCI runtime create failed: container_ linux. go:380: starting container process

The reason is that a startup script does not have execution permission

Solution:

Give the startup script execution permission: chmod +x entrypoint.sh

1. The container startup script defined by docker-compose is entrypoint: ./entrypoint.sh, this script must have executable permissions on the host
2. For images created by Dockerfile, the startup scripts in CMD also need to have execution permissions

SpringBoot Startup Error: Failed to start component [Connector[HTTP/1.1-8080]]

Failed to start component [Connector[HTTP/1.1-8080]]

The following error is reported when starting springboot:

Failed to start component [Connector[HTTP/1.1-8080

protocol handler start failed

Solution:
It is the port number occupation problem:
just close the occupied 8080 port number, enter in cmd: netstat -aon|findstr “port number”, find the PID corresponding to 8080 (port number), and then open the task manager. Find the corresponding PID in “Details” and stop the task.