Tag Archives: java

[2022 New Solution] SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder

SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder

Problem introduction:

insert image description here

Problem Analysis:

According to the error message, we can know that the cause of the error is “failed to load the class file org.slf4j.impl.StaticLoggerBinder”, and the error mainly lies in the jar package of slf4j.

Official website explanation:

This error is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop .jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.

 

Solution:

Add a dependency configuration of one of the above package files to the pom file of the Maven project, as follows:

<dependency span>>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-nop</artifactId>
  <version>1.7.2</version>
</dependency> 

Over!!!

[2022 New Solution] Error:java: Compilation failed: internal java compiler error

Error Reason

The reason for this error is mainly because of the jdk version problem, There are two reasons here, One is that the compiled version does not match, The other is that the current project jdk version does not support.

1:mac select Preferences

windows find Setting

Find Java Compiler

Select 1.8 on the right

2: Find File ->Project Structure->Project Settings

Choose 8

Choose 8

[Solved] EurekaServerApplication: Failed to retrieve application JMX service URL

EurekaServerApplication: Failed to retrieve application JMX service URL

Import a spring cloud project, and report the following error at startup:

EurekaServerApplication: Failed to retrieve application JMX service URL

insert picture description here

Error message

EureKaServerApplication:Failed to retrieve application JMX service URL

Solution:

Select the project ——>Then select the spring boot plugin, Find to the startup project, There is a spring boot option,
Cancel the Enable JMX agent option

insert picture description here

Click on Edit configuration templates >>spring boot >>modify options

insert picture description here

Click Disable JMX agent

insert picture description here

Click Apply >> OK
agent
insert here Image description

Click Apply >> OK
to rerun main entry

[Solved] nacos Error: com.alibaba.nacos.api.exception.NacosException: failed to req API:/nacos/v1/ns/instance

2021-12-18 11:39:44.536 ERROR 26756 --- [           main] c.a.c.n.registry.NacosServiceRegistry    : nacos registry, cs-qq-guild register failed...NacosRegistration{nacosDiscoveryProperties=NacosDiscoveryProperties{serverAddr='xxxx:8848', endpoint='', namespace='xxxx', watchDelay=30000, logName='', service='xxx', weight=1.0, clusterName='DEFAULT', group='xxx', namingLoadCacheAtStart='false', metadata={appname=xxx, preserved.register.source=SPRING_CLOUD, version=0.0.1}, registerEnabled=true, ip='xxx', networkInterface='', port=5203, secure=false, accessKey='', secretKey='', heartBeatInterval=null, heartBeatTimeout=null, ipDeleteTimeout=null, failFast=true}},

com.alibaba.nacos.api.exception.NacosException: Request nacos server failed: 
	at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:279) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.doRegisterService(NamingGrpcClientProxy.java:129) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.registerService(NamingGrpcClientProxy.java:115) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate.registerService(NamingClientProxyDelegate.java:95) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:145) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:74) ~[spring-cloud-starter-alibaba-nacos-discovery-2.2.7.RELEASE.jar:2.2.7.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.register(AbstractAutoServiceRegistration.java:239) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration.register(NacosAutoServiceRegistration.java:78) [spring-cloud-starter-alibaba-nacos-discovery-2.2.7.RELEASE.jar:2.2.7.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:138) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.bind(AbstractAutoServiceRegistration.java:101) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:88) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:47) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:165) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at com.yzycoc.discord.QqGuildApplication.main(QqGuildApplication.java:33) [classes/:na]
Caused by: com.alibaba.nacos.api.exception.NacosException: Client not connected,current status:STARTING
	at com.alibaba.nacos.common.remote.client.RpcClient.request(RpcClient.java:655) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.common.remote.client.RpcClient.request(RpcClient.java:635) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:269) ~[nacos-client-2.0.3.jar:na]
	... 25 common frames omitted

nacos can start normally, but the microservice can’t be registered, resulting in compilation errors
The previous day it worked fine, but today the above error appears in the startup

My side because the address of nacos is localhost:8848 as configured in application.yml
And the address of nacos we started is 198.168.52.12 (why suddenly become this address? I don’t understand)

Solution:

Modify nacos/conf/application.properties file

在这里插入图片描述

2. If it doesn’t work, you can try to delete the nacos cache

Local cache directory default path: ${user.home}/nacos/naming/public

3. If you can’t do it, we recommend uninstalling and reinstalling.

[Solved] JPA query data error: Page 1 of 0 containing UNKNOWN instances

The reason for the error is that there is an empty object according to your query condition, that is, it is not checked. Then double-check the conditions you wrote.
I reported an error because the previous code used cb.equal(root.get(“userName”), res.getName()), which is an absolute query. I copied the previous code directly, but now I want to change it to a fuzzy query, cb.equal(root.get(“userName”), “%” + res.getName().trim() + “%”), here you can see that I only changed the parameter value to a fuzzy query, but the condition is still used equal absolute query reported an error, I searched for more than half an hour to find, and then changed to cb.like(root.get(“userName “), “%” + res.getName().trim() + “%”) and it works.

Specification<TUser> specification = (root, query, cb) -> {
            List<Predicate> predicates = Lists.newArrayList();
            predicates.add(cb.or(cb.equal(root.get("role"), StateEnum.ecgDoctor.name()), cb.equal(root.get("role"), StateEnum.intern.name())));
            //Add name condition
            if (res.getName() != null) {
                predicates.add(cb.like(root.get("userName"), "%" + res.getName().trim() + "%"));
            }
            if (res.getPhoneno() != null) {
                predicates.add(cb.like(root.get("phone"), "%" + res.getPhoneno().trim() + "%"));
            }
            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
        };

To sum up, if you use absolute queries in the future, write it like this

//Add name condition
if (res.getName() != null) {
    predicates.add(cb.equal(root.get("userName"), res.getName().trim()));
}

Fuzzy queries are written like this.

//Add name condition
if (res.getName() != null) {
    predicates.add(cb.equal(root.get("userName"), "%" + res.getName().trim() + "%"));
}

This will not be wrong.

Also note that the paging inside the JPA, page is from 0, there is root.get(“property”), the name of this property is the name of the entity class inside, is this private String userName, this @Column(name = “user_name”) is the name of the database, do not get confused.

@Column(name = "user_name")
private String userName;

[Solved] Maven Project Packaging Error: Unable to find main class

I. Description of the problem

When I use the Maven aggregation project to package the parent project for packaging, I get an error :Unable to find main class which probably means that the main startup class cannot be found

insert image description here

2. How to Solve

The project contains modules of some tool classes, and the tool class modules do not need us to be started, It is only provided for other interface service references, No need to start means no main startup class, but the pom file of the parent project references the springboot packaging plugin spring-boot-maven-plugin, namely:

 <plugins> 
            <plugin>
                <groupId>org.springframework.boot</ groupId>
                <artifactId>spring-boot-maven-plugin&lt ;/artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId&gt ;
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>

So when packaging, mvn will scan all dependent modules. If it finds that there is no main startup class under a module, it will report an error.

3. Solution

My solution is: Comment out the packaged plugin spring-boot-maven-plugin of the parent project and then package/install it

Insert picture description here
You can see that the packaging is successful

[Solved] IDEA Maven Error: Cannot resolve xxx & Maven Dependencies Error

Prerequisites

Premise: Make sure the dependencies in Maven are correct, Don’t make mistakes such as missing letters.
If you are worried, you can go to the official website to search, and copy and paste it again.
Official website link: https://mvnrepository.com/

scene

Importing a new project,or other reasons,maven refresh is also useless, it reports error as show below:

Solution:

1. First, Clear the cache, Click and restart IDEA.

2. Close IDEA, Open the project folder

Find .idea in the project, delete workspace.xml

3. Re-open IDEA, find Maven on the right

Double-click clean

Wait for the console to appear BUILD SUCCESS

Find install under maven again, Double-click it and the download log shown below will appear.

Wait it over, and BUILD SUCCESS will appear:

Click the Reload button in the Maven component again, wait for the bottom progress bar to end

4. Solve the Dependencis report in Maven

First, Open the file pom.xml

Then delete the content in the tag dependencies [recommended to use Ctrl + x]

Click the Reload button in the Maven component again, wait for the bottom progress bar to finish. [dependencies disappears at this time]

Then in pom.xml, use the shortcut key Ctrl + z to return

(If you are using Ctrl + x , you can use Ctrl + v to paste)

Let the dependencies content appear again,return to the previous state.

The last step: click the Reload button in the Maven component again, wait for the bottom progress bar to finish. [At this time,dependencies appears and no longer reports an error]

Final effect:

Finally, it is solved.

How to Solve jmeter Install Error (Three Common Errors)

Error 1: jmeter is not an internal command

1. New environment variables

Variable name: JMETER_HOME

Variable value:location where jmeter is installed(such as: D:\othersoftware\jmeter\apache-jmeter-5.5)

2. Edit CLASSPATH(Separate with a semicolon when there are multiple CLASSPATHs)

CLASSPATH:%JMETER_HOME%\lib\ext\ApacheJMeter_core.jar;%JMETER_HOME%\lib\jorphan.jar

3. Edit path(If there are multiple Paths, separate them with semicolons)

path: %JMETER_HOME%\bin, then click OK

Enter jmeter -v on the command line to display the version number and the configuration is successful

Error 2: the Java executable or version could not be found, Please check your Java installation

1. Install jdk

2. Configure environment variables

Add JAVA_HOME: JDK installation location

EDIT CLASSPATH: %JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar

edit path: %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin

Save, Enter java -version on the command line to display the version number and the configuration is successful

Error 3: error: ‘findstr’ is not an internal or external command, nor a runnable program or batch file

Add: %SystemRoot%/system32;%SystemRoot%; to Path in the configuration environment

Save, Enter jmeter in cmd to start

Gephi cannot find Java 1.8 or higher [How to Solve]

Previously installed Gephi and configured the Java environment, but not used for more than a year, recently opened Gephi reported an error:

cannot find Java 1.8 or higher

I followed the [online tutorial] to set the jdkhome variable in Gephi.conf as follows:

jdkhome="C:/Users/username/AppData/LocalLow/Oracle/Java/jdk11.0.9_x64& #34;

Another error was reported:

Cannot locate java installation in specified jdkhome

I read a bunch of posts on the Internet again, guess that my Java is not installed in the default path, but installed in the D drive, And the Gephi.conf file should only use Associate to the installation path of Java to, reconfigure:

jdkhome="D:/Program Files/JAVA sdk"

Gephi can be opened normally.

[Solved] Axis Failed to Import webService: No support for attachments

The client generated by Axis, Error when importing webService:

AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode:
 faultString: java.lang.RuntimeException: No support for attachments
 faultActor:
 faultNode:
 faultDetail:
{http://xml.apache.org/axis/}stackTrace:java.lang.RuntimeException: No support for attachments
at org.apache.axis.Message.setup(Message.java:372)
at org.apache.axis.Message.&lt;init&gt;(Message.java:235)
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:779)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)

Problem Reason

Missing jars: mail.jar and activation.jar

Solution

Introduce dependencies



    javax.mail
    mail
    1.4.7



    javax.activation
    activation
    1.1.1