Tag Archives: java

java.text.ParseException: Unparseable date: “2021-06-24“

String to date:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
String nowDate = new SimpleDateFormat("yyyy-mm-dd").format(new Date());

Format must be written, otherwise an error will be reported. Conversion exception: Java. Text. Parseexception: unparseable date

Date subtraction calculation days reference:

int dayNum = (int) ((d2.getTime() - d1.getTime())/(1000 * 3600 * 24));

Tomcat startup project warning: org.apache.jasper.servlet.tldscanner.scanjars at least one jar has been scanned for TLD but does not contain TLD

Problem:
start springmvc project, start error:
org.apache.jasper.servlet.tldscanner.scanjars at least one jar is scanned for TLD, but it does not contain TLD. Enable debug logging for this logger to get a complete list of jars that have been scanned but in which TLDs were not found. Skipping unnecessary jars during scanning can reduce startup time and JSP compilation time.

Solution:
1. Find the catalina.properties file in the conf directory under your Tomcat installation path:

2. Change the content after the equal sign in the figure below to *. Jar

3. Then reconfigure your own server and restart it.

org.springframework.beans.factory.UnsatisfiedDependencyException

Phenomenon service failed to start
the following error log

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/D:/IT/maven/repository/io/springfox/springfox-spring-web/2.7.0/springfox-spring-web-2.7.0.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'adminCompanyController' method 
public java.lang.Object com.qqwl.gold.controller.AdminCompanyController.setExcellent(java.lang.Integer,java.lang.Integer)
to {POST /admin/jyCompany/setType}: There is already 'adminCompanyController' bean method
public java.lang.Object com.qqwl.gold.controller.AdminCompanyController.setType(java.lang.Integer,java.lang.Integer) mapped.

Cause analysis: the mapping path with the same name leads to

Error creating bean with name xxxxxx : unsatisfied dependency…

Check the mybatis configuration file to see if scanning is configured. My error is because only one PO class is configured for package scanning, and the Po class of another table is not scanned

terms of settlement:

Add the fully qualified name of the Po class to the parametertype of the XML Mapping file, or write the Po class in a package

java.lang.Throwable: Substituted for the exception com.bea.xml.SchemaTypeLoaderException which lack

Weblogic error message:

 <Error> <Console> <AdminServer> <[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'> <webuser> <> <> <1624366734323> <BEA-240003> <Administration Console encountered the following error: weblogic.management.provider.UpdateException: [Management:141191]The prepare phase of the configuration update failed with an exception.
        at weblogic.management.provider.internal.RuntimeAccessDeploymentReceiverService.updateDeploymentContext(RuntimeAccessDeploymentReceiverService.java:777)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doUpdateDeploymentContextCallback(DeploymentReceiverCallbackDeliverer.java:147)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.updateDeploymentContext(DeploymentReceiverCallbackDeliverer.java:28)
        at weblogic.deploy.service.internal.statemachines.targetserver.ReceivedPrepare.callDeploymentReceivers(ReceivedPrepare.java:203)
        at weblogic.deploy.service.internal.statemachines.targetserver.ReceivedPrepare.handlePrepare(ReceivedPrepare.java:112)
        at weblogic.deploy.service.internal.statemachines.targetserver.ReceivedPrepare.receivedPrepare(ReceivedPrepare.java:52)
        at weblogic.deploy.service.internal.targetserver.TargetRequestImpl.run(TargetRequestImpl.java:211)
        at weblogic.deploy.service.internal.transport.CommonMessageReceiver$1.run(CommonMessageReceiver.java:457)
        at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:553)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)
Caused by: java.lang.Throwable: Substituted for the exception com.bea.xml.SchemaTypeLoaderException which lacks a String contructor, original message - XML-BEANS compiled schema: Could not locate compiled schema resource schemacom_bea_xml/system/s0BC706AE0F5CDA9F4183EB0C5C434EEA/keystores8f60elemtype.xsb (schemacom_bea_xml.system.s0BC706AE0F5CDA9F4183EB0C5C434EEA.keystores8f60elemtype) - code 0
        at com.bea.xbean.schema.SchemaTypeSystemImpl$XsbReader.<init>(SchemaTypeSystemImpl.java:1519)
        at com.bea.xbean.schema.SchemaTypeSystemImpl.resolveHandle(SchemaTypeSystemImpl.java:3505)
        at com.bea.xml.SchemaComponent$Ref.getComponent(SchemaComponent.java:113)
        at com.bea.xml.SchemaType$Ref.get(SchemaType.java:872)
        at com.bea.xbean.schema.SchemaParticleImpl.getType(SchemaParticleImpl.java:194)
        at com.bea.xbean.validator.Validator.beginEvent(Validator.java:389)
        at com.bea.xbean.validator.Validator.nextEvent(Validator.java:241)
        at com.bea.xbean.validator.ValidatingXMLStreamReader.validate_event(ValidatingXMLStreamReader.java:581)
        at com.bea.xbean.validator.ValidatingXMLStreamReader.next(ValidatingXMLStreamReader.java:546)
        at com.bea.xbean.richParser.XMLStreamReaderExtImpl.next(XMLStreamReaderExtImpl.java:1122)
        at com.bea.staxb.runtime.internal.MarshalStreamUtils.advanceToNextStartElement(MarshalStreamUtils.java:120)
        at com.bea.staxb.runtime.internal.UnmarshalResult.advanceToNextStartElement(UnmarshalResult.java:830)
        at com.bea.staxb.runtime.internal.ByNameUnmarshaller.deserializeContents(ByNameUnmarshaller.java:57)
        at com.bea.staxb.runtime.internal.AttributeUnmarshaller.unmarshalIntoIntermediary(AttributeUnmarshaller.java:47)
        at com.bea.staxb.runtime.internal.LiteralUnmarshalResult.unmarshalElementProperty(LiteralUnmarshalResult.java:184)
        at com.bea.staxb.runtime.internal.LiteralUnmarshalResult.extractAndFillElementProp(LiteralUnmarshalResult.java:156)
        at com.bea.staxb.runtime.internal.ByNameUnmarshaller.deserializeContents(ByNameUnmarshaller.java:67)
        at com.bea.staxb.runtime.internal.AttributeUnmarshaller.unmarshalIntoIntermediary(AttributeUnmarshaller.java:47)
        at com.bea.staxb.runtime.internal.UnmarshalResult.unmarshalBindingType(UnmarshalResult.java:199)
        at com.bea.staxb.runtime.internal.UnmarshalResult.unmarshalDocument(UnmarshalResult.java:169)
        at com.bea.staxb.runtime.internal.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:67)
        at weblogic.descriptor.internal.MarshallerFactory$1.createDescriptor(MarshallerFactory.java:150)
        at weblogic.descriptor.BasicDescriptorManager.createDescriptor(BasicDescriptorManager.java:327)
        at weblogic.management.provider.internal.RuntimeAccessDeploymentReceiverService.handleConfigTreeLoad(RuntimeAccessDeploymentReceiverService.java:1092)
        at weblogic.management.provider.internal.RuntimeAccessDeploymentReceiverService.updateDeploymentContext(RuntimeAccessDeploymentReceiverService.java:697)
>

Because SSL is configured in Weblogic, an error is reported during activation. There is a cluster in the project, and this error occurs,

solve:

Stop the server services corresponding to other cluster nodes, and then modify and activate them. At this time, the changes can be activated normally.

If one node is configured in the cluster, other nodes need to be configured.

TypeError: Failed to execute ‘fetch‘ on ‘Window‘: Request with GET/HEAD method cannot have body.

Swagger error:

TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

reason:

The @ ResponseBody is used. Because the get method is declared in the method, the @ requestbody is used  
Get cannot get parameters using.

solve:

Getmapping   Change to postmapping

The problem of date format conversion between springboot and front end

A unique experience of stepping on a pit

When there is a date of string type in the current page request, the Java backend needs to convert the string type to the date type. In springboot, the convertor interface is implemented through the custom dateconverterconfig class, which is put into the spring container for conversion.

! Here’s the key point:
when I knock step by step, there is still an exception * * here was an unexpected error (type = bad request, status = 400). * * *. Finally, I found that the converter’s package was wrong
remember: import org.springframework.core.convert.converter.converter;

package com.jiansheng.util;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: Jiansheng
 * @DateTime: 2021/6/27 10:35
 * @Description:Date
 */
@Component
public class DateConverterConfig implements Converter<String, Date> {

    private static final List<String> formarts = new ArrayList<>(4);
    static{
        formarts.add("yyyy-MM");
        formarts.add("yyyy-MM-dd");
        formarts.add("yyyy-MM-dd HH:mm");
        formarts.add("yyyy-MM-dd HH:mm:ss");
    }

    @Override
    public Date convert(String source) {
        String value = source.trim();
        if ("".equals(value)) {
            return null;
        }
        if(source.matches("^\\d{4}-\\d{1,2}$")){
            return parseDate(source, formarts.get(0));
        }else if(source.matches("^\\d{4}-\\d{1,2}-\\d{1,2}$")){
            return parseDate(source, formarts.get(1));
        }else if(source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}$")){
            return parseDate(source, formarts.get(2));
        }else if(source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}:\\d{1,2}$")){
            return parseDate(source, formarts.get(3));
        }else {
            throw new IllegalArgumentException("Invalid boolean value '" + source + "'");
        }
    }

    /**
     * Formatting the date
     * @param dateStr String Character type date
     * @param format String Format
     * @return Date Date
     */
    public  Date parseDate(String dateStr, String format) {
        Date date=null;
        try {
            DateFormat dateFormat = new SimpleDateFormat(format);
            date = dateFormat.parse(dateStr);
        } catch (Exception e) {

        }
        return date;
    }

}

Jiansheng

[Solved] Cannot find class: com.mysql.jdbc.Driver

When using mybatis to write the entry instance for the first time, I encountered the error of cannot find class: com.mysql.jdbc.driver database property configuration file content:

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/exercise?serverTimezone=GMT%2B8
jdbc.user=root
jdbc.password=1996mysqlyue

Mybatis configuration part:

            <!--Four basic information for connecting to the database-->
            <dataSource type="POOLED">
                <property name="driver" value="${jdbc.driver}"/>
                <property name="url" value="${jdbc.url}"/>
                <property name="username" value="${jdbc.user}"/>
                <property name="password" value="${jdbc.password}"/>
            </dataSource>

Confirm that there is no space in the quotation marks of the value value in the configuration file, and there is no space in the configuration information of the database property file, but still report an error
subsequent solution:
modified the dependency version of MySQL connector introduced by Maven.

[Solved] Flowable Start Error: ClassCastException: java.time.LocalDateTime cannot be cast to java.lang.String

Springboot2 + MySQL integrated flowable6.6.0, failed to start

In liquibase.changelog.standardchangeloghistoryservice, there is such a code:

Object tmpDateExecuted = rs.get("DATEEXECUTED");
    Date dateExecuted = null;
    if (tmpDateExecuted instanceof Date) {
        dateExecuted = (Date)tmpDateExecuted;
    } else {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            dateExecuted = df.parse((String)tmpDateExecuted);
        } catch (ParseException var24) {
    }
}

The dateexecuted field in the database is of timestamp type. When the version of the database driver package used is relatively new (8.0.23 is used here), the returned type is localdatetime. If it is strongly converted to string, an error will be reported

Modify the driver package version to 8.0.19, and the service starts normally

[Solved] Failed to start bean ‘eurekaAutoServiceRegistration‘; nested exception is java.lang.NullPointerExce

When using spring-cloud-starter-netflix-eureka-client, the following exception was encountered when starting the project. Failed to start bean ‘eurekaAutoServiceRegistration’; nested exception is java.lang.NullPointerExce

org.springframework.context.ApplicationContextException: Failed to start bean 'eurekaAutoServiceRegistration'; nested exception is java.lang.NullPointerException
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:880) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at com.shanba.SbnsyhManageApplication.main(SbnsyhManageApplication.java:12) [classes/:na]
Caused by: java.lang.NullPointerException: null
	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:56) ~[spring-cloud-netflix-eureka-client-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:37) ~[spring-cloud-netflix-eureka-client-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:73) ~[spring-cloud-netflix-eureka-client-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	... 14 common frames omitted

Reason: spring cloud’s jar package is introduced in POM in sequence

Wrong reference

<!--thymeleaf Template engine configuration-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--Web依赖-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

Normal reference

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--thymeleaf Template engine configuration-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--Web-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>

[Solved] JDK Install Error /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

CentOS 7.6 JDK installation, download the following JDK package

wget https://mirrors.huaweicloud.com/java/jdk/8u201-b09/jdk-8u201-linux-i586.tar.gz

After installation. After configuring environment variables, execute Java – version to report an error

-bash: /root/jdk1.8.0_201/bin/java: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory


Solution
Just run sudo yum install glibc.i686
Then look at java -version OK!

[Solved] IDEA Import springboot Project Error: Cannot resolve plugin org.springframework.boot:spring-boot-maven-plugin:<unknown>

Today, after pulling the springboot project from gitee, I found that idea directly reported an error. The error is as follows:

Cannot resolve plugin org.springframework. boot:spring-boot-maven-plugin :

At first, I thought it was an error in the project. Later, baidu found that the default Maven configuration file and the default local warehouse address were used in the configuration of the project.

resolvent:

Open file — & gt; Settings –> Build, Execution, Deploymen –> Build Tools –>   Maven, find the user Maven configuration file and local warehouse address, and modify it to the local configuration file path and warehouse address.

Before revision:

After modification:

Refresh Maven again and solve the problem