Tag Archives: java

Springboot2.6X version integrate knife4j error [How to Solve]

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.13.jar:5.3.13]
	at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.13.jar:5.3.13]
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.13.jar:5.3.13]
	at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.13.jar:5.3.13]
	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.13.jar:5.3.13]
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935) ~[spring-context-5.3.13.jar:5.3.13]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.13.jar:5.3.13]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.1.jar:2.6.1]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-2.6.1.jar:2.6.1]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.6.1.jar:2.6.1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.1.jar:2.6.1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.1.jar:2.6.1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.1.jar:2.6.1]
	at com.fern.hfet.HfetApplication.main(HfetApplication.java:14) ~[classes/:na]
Caused by: java.lang.NullPointerException: null
	at springfox.documentation.spring.web.WebMvcPatternsRequestConditionWrapper.getPatterns(WebMvcPatternsRequestConditionWrapper.java:56) ~[springfox-spring-webmvc-3.0.0.jar:3.0.0]
	at springfox.documentation.RequestHandler.sortedPaths(RequestHandler.java:113) ~[springfox-core-3.0.0.jar:3.0.0]
	at springfox.documentation.spi.service.contexts.Orderings.lambda$byPatternsCondition$3(Orderings.java:89) ~[springfox-spi-3.0.0.jar:3.0.0]
	at java.base/java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:469) ~[na:na]
	at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:355) ~[na:na]
	at java.base/java.util.TimSort.sort(TimSort.java:220) ~[na:na]
	at java.base/java.util.Arrays.sort(Arrays.java:1515) ~[na:na]
	at java.base/java.util.ArrayList.sort(ArrayList.java:1750) ~[na:na]
	at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:392) ~[na:na]
	at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258) ~[na:na]
	at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258) ~[na:na]
	at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258) ~[na:na]
	at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258) ~[na:na]
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485) ~[na:na]
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na]
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[na:na]
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[na:na]
	at springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider.requestHandlers(WebMvcRequestHandlerProvider.java:81) ~[springfox-spring-webmvc-3.0.0.jar:3.0.0]
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[na:na]
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655) ~[na:na]
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[na:na]
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na]
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[na:na]
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[na:na]
	at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.withDefaults(AbstractDocumentationPluginsBootstrapper.java:107) ~[springfox-spring-web-3.0.0.jar:3.0.0]
	at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.buildContext(AbstractDocumentationPluginsBootstrapper.java:91) ~[springfox-spring-web-3.0.0.jar:3.0.0]
	at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.bootstrapDocumentationPlugins(AbstractDocumentationPluginsBootstrapper.java:82) ~[springfox-spring-web-3.0.0.jar:3.0.0]
	at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.start(DocumentationPluginsBootstrapper.java:100) ~[springfox-spring-web-3.0.0.jar:3.0.0]
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.13.jar:5.3.13]
	... 14 common frames omitted

Disconnected from the target VM, address: '127.0.0.1:65104', transport: 'socket'

Process finished with exit code 1

The reason for this problem is: springboot2.6.x and the previous version use PATH_PATTERN_PARSER by default, while knife4j’s springfox uses ANT_PATH_MATCHER. Springboot’s yml file configures url matching rules

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

[Solved] Swagger request error: error:getaddrinfo ENOTFOUND

Swagger request error: error: getaddrinfo enotfound

This is the problem I encountered. Maybe everyone encountered it in different ways. I just said the problems I encountered and my solutions
my problem is that when I create a new data table and put it in the test environment, the data table does not move to the test environment, so this error is reported:
solution: import the newly created data table in the test environment (formal environment), and the interface access is normal.

Eclipse: How to Close XML validation (xml file Error)

Eclipse turns off English spell checking and XML validation

To solve the problem, the servlet can run, but the XML file is red

Mode 1:

Windows–> Preferences–> XML –> XML Files –> Validate

Find validate and uncheck build

Mode 2:

Windows–> Preferences–> XML(Wild Web Developer)-> Validate& Resolution

Cancel enable validate

Or change both enable namespaces validate and enable schema based} validate to never

Then click apply and it will be OK

The first one, I don’t know whether it’s my eclipse version or something. I didn’t find that one. The second one can solve this problem. I hope it can help you!!

[Solved] activiti integrate error: GlobalAuthenticationConfigurerAdapter.class does not exist

@EnableSwagger2
@SpringBootApplication(scanBasePackages = {"cn.com.ten"} ,exclude = {org.activiti.spring.boot.SecurityAutoConfiguration.class})
@MapperScan(basePackages = {"cn.com.ten.**.dao"})
public class SystemEtlApplication {

    public static void main(String[] args) {
        SpringApplication.run(SystemEtlApplication.class, args);
    }

}

Springboot integration activiti reported an error

Caused by: java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.class]
cannot be opened because it does not exist

 

Solution:

Add springbootapplication on the startup class

exclude = {org.activiti.spring.boot.SecurityAutoConfiguration.class}

[Solved] weblogic12c start the project error: BeanFactoryAware is missing

1. The project is not a spring project and does not reference any spring related packages
2. No error is reported when starting under Tomcat
3. No error is reported in weblogic10g and no error is reported in 12C
the error information is as follows:


weblogic.management.DeploymentException: java.lang.ClassNotFoundException: org.springframework.beans.factory.BeanFactoryAware
 at weblogic.application.internal.BaseDeployment.throwAppException(BaseDeployment.java:131)
 at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:245)
 at weblogic.application.internal.SingleModuleDeployment.prepare(SingleModuleDeployment.java:53)
 at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:158)
 at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:61)
 Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassNotFoundException: org.springframework.beans.factory.BeanFactoryAware
 at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:981)
 at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:942)
 at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:83)
 at weblogic.utils.classloaders.GenericClassLoader.doFindClass(GenericClassLoader.java:564)
 at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:500)
 Truncated. see log file for complete stacktrace

Through the error message, it is judged that it is caused by a spring bean, but my project does not reference spring at all. It is suspected that it is caused by jar package conflict

Solution:
If Druid’s jar package is referenced in your project, it’s probably the problem. Upgrade the Druid jar package or downgrade the version of the Druid jar package in the project. We are from druid-1.0.10 upgrade to druid-1.0.3 problem solving. Druid’s jar package download address is attached.

https://archive.apache.org/dist/druid/

How to Solve Log4j 2.5 upgrade to 2.15 error

Question

Log4j2 is used in the project. Due to the use of global asynchronous log printing, it is also necessary to introduce the dependency of disruptor. The version dependency of log4j2 and disruptor used last is as follows:

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.11.1</version>
</dependency>
<!-- log4j2 AsyncLogger need disruptor-->
<dependency>
    <groupId>com.lmax</groupId>
    <artifactId>disruptor</artifactId>
    <version>3.2.0</version>
</dependency>

At the beginning of the project (before the logger of log4j2 is used for the first time), enable global asynchronous log printing through code:

// use asyncLogger for log4j2 framework
System.setProperty("Log4jContextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");

However, the errors reported after starting the project are as follows:

java.lang.NoSuchMethodError: com.lmax.disruptor.dsl.Disruptor.<init>(Lcom/lmax/disruptor/EventFactory;ILjava/util/concurrent/ThreadFactory;Lcom/lmax/disruptor/dsl/ProducerType;Lcom/lmax/disruptor/WaitStrategy;)V
        at org.apache.logging.log4j.core.async.AsyncLoggerDisruptor.start(AsyncLoggerDisruptor.java:97)
        at org.apache.logging.log4j.core.async.AsyncLoggerContext.start(AsyncLoggerContext.java:75)
	at .......

Solution:

The problem is caused by the lower version of the disruptor. Just change the version to the newer version:

<dependency>
    <groupId>com.lmax</groupId>
    <artifactId>disruptor</artifactId>
    <version>3.4.2</version>
</dependency>

How to Solve Springboot use thymeleaf template error

When using the thymeleaf template for the first time, the following error is reported when starting:

The following method did not exist: 
org.thymeleaf.spring5.SpringTemplateEngine.setRenderHiddenMarkersBeforeCheckboxes(Z)V

The reason for this error is that the version of springboot is incompatible with the version of thymeleaf template. Add the following content to the <properties> tag:

<thymeleaf-spring5.version>3.0.9.RELEASE</thymeleaf-spring5.version>
<thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>

After adding, you can start springboot

JUnit tests mybatis-plus error: null pointer [How to Solve]

Question:

Because the project uses microservices, a service is created in the microservices to write mybatis plus in order to save trouble. However, a null pointer error occurs when JUnit tests after writing according to the official website documents.

Test class of official website document:

An error occurred:

The value of usermapper was found to be empty

By checking the data, it is found that this is because ordinary classes can’t use springbeans, so ordinary test classes can’t get beans, so they report null pointers. Therefore, we need to make the test class get the bean.

Solution:

Add test dependency:

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

And add notes on the test class:

@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)

solve the problem

Java error: java.lang.NoSuchMethodError

The Java runtime reports an error
the postman test reports an error of 500. The exception information is displayed as follows:


reason: first, check whether there is a method of this attribute in the previous class. If so, it is mostly a problem of dependency conflict. In general, it may be that classes with the same package name and class name are introduced. The order in which dependencies are introduced in the POM file of the project is inconsistent, resulting in the use of other people’s classes with the same package and the same name, and there is no corresponding entity class attribute paramscheckresult. An error will be reported in the result. Query the full path name of the class you introduced.

 

Methods:

ProtectionDomain pd = Response.class.getProtectionDomain();
CodeSource cs = pd.getCodeSource();
System.out.println(cs.getLocation().toString());

Print result: the full path name of the imported class will be displayed

easy-pdf-merge Error: java: command not found [How to Solve]

The phenomena are as follows:

Error: Command failed: java -jar  "/var/task/node_modules/easy-pdf-merge/jar/pdfbox.jar" PDFMerger "samplepdf1.pdf" "samplepdf2.pdf" "merged.pdf"
/bin/sh: java: command not found

    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:198:13)
    at maybeClose (internal/child_process.js:982:16)
    at Socket.stream.socket.on (internal/child_process.js:389:11)
    at Socket.emit (events.js:198:13)
    at Pipe._handle.close (net.js:607:12)
  killed: false,
  code: 127,
  signal: null,
  cmd:
   'java -jar  "/var/task/node_modules/easy-pdf-merge/jar/pdfbox.jar" PDFMerger "samplepdf1.pdf" "samplepdf2.pdf" "merged.pdf"' }

Solution: java: command not found, install jdk to solve it, or configure the green version of jdk to environment variables

BigDecimal Error: NumberFormatException [How to Solve]

Question:

1. This problem occurs first because it is not handled properly during type conversion, and non null judgment is required

Solution:

String val =””;

if (val!=null && !val.equals("")){
merchantDetailData.setTransactionAmount(new BigDecimal(StringUtils.nvl(list.get(9))));
}

Only when the judgment value is not equal to null and not equal to “”