Tag Archives: java

[Solved] jar file Execute Error: power shell error: unable to access jarfile

 

Problem description

When using the configuration task of vscode, there are problems in executing the jar file, so there are the following solutions.

preparation

Software: vscode
environment: windows10

How to configure

1. Create a task and execute the jar file:

2. Configurable parameters must be placed later

-Dkafka.base.client.bootstrapServers=192.168.75.129:9092

How does it work

1. Run profile location

2. Find the executable file name

More

Building Java code
You can use Maven to perform multiple build lifecycle goals, including compiling project code, creating library packages (such as JAR files), and installing libraries in a local Maven dependency repository
To attempt a build, issue the following command from the command line.
mvn compile

This will run Maven and tell it to perform a compile of the target. When it is done, you should find the compiled .class file in the target/classes directory.
Since you are unlikely to want to distribute or use the .class files directly, you may want to run the package target instead:
mvn package

The package target will compile the Java code, run any tests, and package the code up in the completion target directory via an internal JAR file. the name of the JAR file will be based on the project's <artifactId> and <version>.
For example, given the previous minimal pom.xml file, the JAR file will be named kiwi-0.7.0.jar.

To execute the JAR file, run.
java -jar F:\WorkSoftware\Kafka\kiwi-0.7.0.jar -Dkafka.base.client.bootstrapServers=192.168.75.129:9092

If you change the value of <packaging> "jar" to "war", the result will be a WAR file in the target directory instead of a JAR file.

kakfa Create topic Error: java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 3 larger than available brokers: 2.

Error message:

java. util. concurrent. ExecutionException: org. apache. kafka. common. errors. InvalidReplicationFactorException: Replication factor: 3 larger than available brokers: 2.

According to the error message, the number of copies of topic to be created is 3 and the number of brokers is 2. Indicates that Kafka did not get the stored brokers information in zookeeper.

Check:

Whether the Kafka cluster is enabled normally. At the same time, it should be noted that the number of topic replicas created cannot be greater than the number of surviving brokers in the cluster

Lsof – I check whether each Kafka node is normal

Spring MVC project error: Namespace in turns red

Namespace in <mapper namespace> turns red

Solution:

The XML file header language should be changed to the mapper mapping instead of the config
previously used as follows:

<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

Change to

<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

Create folders with different functions

Linux Error: audit: backlog limit exceeded [How to Solve]

Phenomenon description:

Linux SSH cannot be connected and can be pinged. The login interface will give an error prompt audit: backlog limit exceeded

audit:backlog limit exceeded audit:backlog limit exceeded audit:backlog limit exceeded audit:backlog limit exceeded audit:backlog limit exceeded audit:backlog limit exceeded audit:backlog limit exceeded audit:backlog limit exceeded ...

Cause analysis:

The error is Linux kernel logs. The reason for the problem is that the audit service performs audit event operations in a busy system, and there is a bottleneck in the buffer, resulting in the system near crash.

Background:

Audit is a service used to record the user’s underlying calls in Linux system. It is used to record the user’s open, exit and other system calls, and write the records to the log file. Audit can add or delete audit rules by using the auditctl command. You can set recording for a user or for a process.

Main command: auditctl audit rules & amp; The system management tool is used to obtain status, add and delete monitoring rules, audit search query audit log tool, and audit report output audit system report

Solution:

You can try to increase the audit buffer to solve this problem.

The default memory page size for Linux is 4096 bytes. You can obtain the page size through the following command: getconf page_ Size, which can be set to N times of paging

View help auditctl – H

View the current default configuration auditctl – S

backlog_ Limit 320 # my centos7 1 only 320 by default

Optimize the audit service and modify the buffer size auditctl – B 8192. If not set, the system defaults to 64bytes

Settings take effect permanently:

Method 1) modify the rule configuration VIM/etc/audit/audit Rules - D - B 8192 - F 1 Parameter Description: – D delete all rules – B set the audit buffer size. If the buffer is full, the kernel will issue a failure flag – f [0|1|2] set the level of audit acquisition error. There are three values of 0/1/2. 0 is no log output; 1 is the output printk log; 2 is the highest level and will output a large amount of log information -e [0|1] enable/disable audit

Method 2) you can also set CHMOD U + X/etc/rc d/rc. local vim /etc/rc. d/rc. local auditctl -b 8192

Springboot startup error: err config is disabled command (Redis Disables Config command)

1. Background description

The project belongs to spring boot, which is always normal. Due to the recent security activity disabling redis’s config command, an error is reported when the project is restarted:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/boot/autoconfigure/session/RedisSessionConfiguration$SpringBootRedisHttpSessionConfiguration.class]: Invocation of init method failed; 
nested exception is org.springframework.data.redis.connection.ClusterCommandExecutionFailureException: ERR config is disabled command; 
nested exception is redis.clients.jedis.exceptions.JedisDataException: ERR config is disabled command; 
nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: ERR config is disabled command; 
nested exception is redis.clients.jedis.exceptions.JedisDataException: ERR config is disabled command

2. Analysis

Check the source code of redishttpsessionconfiguration class (as shown below), and find the input parameter to enable the keyspace notifications function: configurereredisaction.configurereredisaction accepts the injection. The default is new configurenotifykeyspaceeventsaction() in the constructor. Looking at the source code of this class (not posted here), we find that this class is used to configure the “notify keyspace events” function. Then, redis’s config command will be used in the static internal class enablererediskeyspacenotificationsinitializer, Since the config command is disabled, the above exception is reported.

Look at the post-processing condition if (this.configure! =configurereredisaction.no_op) in the static internal class. The solution is obvious here.

The solution is to inject configurereredisaction.NO_OP, do not receive the default configurenotifykeyspaceeventsaction.configureRedisAction.NO_op itself does not do any processing.

private ConfigureRedisAction configureRedisAction;

......

public RedisHttpSessionConfiguration() {
        this.redisFlushMode = RedisFlushMode.ON_SAVE;
        this.cleanupCron = "0 * * * * *";
        this.configureRedisAction = new ConfigureNotifyKeyspaceEventsAction();
    }

......

@Autowired(
        required = false
    )
    public void setConfigureRedisAction(ConfigureRedisAction configureRedisAction) {
        this.configureRedisAction = configureRedisAction;
    }

......

@Bean
    public InitializingBean enableRedisKeyspaceNotificationsInitializer() {
        return new RedisHttpSessionConfiguration.EnableRedisKeyspaceNotificationsInitializer(this.redisConnectionFactory, this.configureRedisAction);
    }
......

static class EnableRedisKeyspaceNotificationsInitializer implements InitializingBean {
        private final RedisConnectionFactory connectionFactory;
        private ConfigureRedisAction configure;

        EnableRedisKeyspaceNotificationsInitializer(RedisConnectionFactory connectionFactory, ConfigureRedisAction configure) {
            this.connectionFactory = connectionFactory;
            this.configure = configure;
        }

        public void afterPropertiesSet() throws Exception {
            if (this.configure != ConfigureRedisAction.NO_OP) {
                RedisConnection connection = this.connectionFactory.getConnection();

                try {
                    this.configure.configure(connection);
                } finally {
                    try {
                        connection.close();
                    } catch (Exception var8) {
                        LogFactory.getLog(this.getClass()).error("Error closing RedisConnection", var8);
                    }

                }

            }
        }
    }

3. Solutions

Inject the default object configurereredisaction.NO_OP, add a configuration item switch to keep unchanged and respond to changes.

package com.abc.test.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.data.redis.config.ConfigureRedisAction;

/**
 * After disabling Redis' config command.
 * Here when the configuration file redis.disableConfig=true inject ConfigureRedisAction.NO_OP to solve the problem, otherwise it is handled by default
 * @author test
 * @version 1.0
 * @date 2021/12/29 15:44
 */
@Configuration
@ConditionalOnProperty(value = "redis.disableConfig", havingValue = "true")
public class HttpSessionConfig {

    @Bean
    public static ConfigureRedisAction configureRedisAction(){
        return ConfigureRedisAction.NO_OP;
    }
}

Time is pressing, over!

[Solved] JAVA connect HBase program is stuck and does not report an error

Let me explain my situation first:

In the HBase shell interface, you can run it with commands, but not with Java API.

HBase and zookeeper configuration files are all OK.

During Java API operation, it is stuck and cannot be connected. Look at the HBase and zookeeper logs. There is no information available.

When the program runs for a long time, it reports an error (intercept a useful line):

java. net. UnknownHostException: can not resolve hadoop01,16020,164077701361

Maybe I can’t recognize Hadoop 01. What’s this?It’s my node hostname.

Here’s how to view it:

1 zkServer.SH check whether there are any leaders, followers, etc. in zookeeper.Mine (is it a zookeeper configuration problem)

2. Check the zookeeper log and enter the logs directory. One of mine is Hadoop 01 and the other is master (previous host name).

At this point, I probably know where the problem is

Possible

1 . Host name and configuration conflict

2 . HBase version data conflict (I have installed different versions)

Solution:

1. Close HBase and zookeeper

2 delete the data file of zookeeper (violence works miracles). Mine is in the data. Pay attention not to delete myid (all three nodes are deleted)

3 restart zookeeper and HBase

Run java code

Finish work

[Solved] SpringBoot Error: org.springframework.http.converter.HttpMessageNotReadableException

SpringBoot Error: org.springframework.http.converter.HttpMessageNotReadableException

 


org.springframework.http.converter.HttpMessageNotReadableException:
Required request body is missing: * * * * *
at.org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:161)
	

After careful investigation, I found that there are no errors in my other codes. Finally, the parameter submission method is wrong, because the @requestbody annotation is mainly used to accept JSON data in post and put methods, so @postmapping should be used here. It’s a perfect solution. I’m really getting farther and farther on the road of rookie

[Solved] swagger Docmentation Access Error: Illegal DefaultValue 1024 for parameter type integer, java.lang.NumberFormatException

Background error reporting problem log

2021-12-30 15:41:24.675  WARN [nio-9008-exec-1] [] i.s.m.p.AbstractSerializableParameter    [421] : Illegal DefaultValue 1024 for parameter type integer

java.lang.NumberFormatException: For input string: ""
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Long.parseLong(Long.java:601)
	at java.lang.Long.valueOf(Long.java:803)
	at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412)
	at sun.reflect.GeneratedMethodAccessor149.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:689)
	at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:755)

Troubleshooting

In abstractserializableparameter.getexample (abstractserializableparameter.java:412) break point debugging. You can find that the value of example is an empty string and execute long Valueof (this.example) will throw ‘Java.lang.numberformatexception’ exception

Solution:

1. modify source code

2. Download the source code and change the if (this.example = = null) judgment to if (this.example = = null | example.isempty())

3. adjust dependency (recommended)

4. Exclude swagger models of swagger2 and add swagger models with version 1.5.21

<!--  Illegal DefaultValue null for parameter type integer  -->
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
            <version>1.5.21</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.10.5</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-models</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

After adjustment, you can see that the new version has modified the decision logic

after the above operations, no error will be reported when accessing the swagger document address.

[Solved] The Bean Validation API is on the classpath but no implementation could be found

Question

When starting the springboot service, the service reports an error. The specific error information is as follows:

Description:
The Bean Validation API is on the classpath but no implementation could be found
Action:
Add an implementation, such as Hibernate Validator, to the classpath

reason:

Dependency in POM

<dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>7.0.0.Final</version>
        </dependency>

And

<dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
            <version>2.2.6.RELEASE</version>
        </dependency>

Conflict.

Solution:

The dependency is deleted because it is not used in the service

<dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>7.0.0.Final</version>
        </dependency>

Restart the service normally.

[Solved] Maven Project Error: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

Tomcat does not publish the jar package added by Maven dependency when publishing the project

Solution:

eclipse project right click -> properties -> Deployment Assembly -> Add -> Java Build Path Entries -> select Maven Dependencies -> Apply -> Finish -> it’s OK
This will publish the corresponding Maven dependencies to tomcat, and tomcat will be able to find the dependencies

Special case: tomcat service (Servers) has more than one project, will also report such an error, the project does not need to start to remove can be

[Solved] Spring Boot Startup Error: Failed to load property source from location ‘classpath:/application-dev.yml‘

Application.yml file format problem

If your project has no configuration errors and the configuration file name is normal, and you still have this problem, it must be a problem with the encoding of your yml file.

Because the encoding format of this file is GBK, the encoding format of the project is UTF-8, there are comments in it, and the comments are garbled, which leads to compilation failure.

Solution:

IDEA open path: File –> Settings –> File Encodings, then change the format of /application.yml to the same as the project, i.e.: UTF-8.
To be on the safe side, change “Project Encoding” to UTF-8 as well.
Restart IDEA, then start the project, OK.

Translated with www.DeepL.com/Translator (free version)