Tag Archives: spring

Springboot uses the Datetimeformat (pattern = “yyyy MM DD HH: mm: SS”) annotation to automatically convert the string to date type error

1.dto

import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * @author: htdd
 * @date: 2022/1/7 11:15
 */
@Data
public class TestDTO implements Serializable {

    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date createTime;
}

2.controller

@PostMapping("test")
public JsonData test(HttpServletRequest request, @RequestBody TestDTO dto) {
    return JsonData.buildSuccess("success");
}

3. An error is reported after a postman request

Postman request

Background error reporting

Error reporting reason:

The general meaning is that the time format does not meet the requirements. After checking the document, the default conversion format for time is

"yyyy-MM-dd'T'HH:mm:ss.SSSZ"  
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"  
"EEE, dd MMM yyyy HH:mm:ss zzz"  
"yyyy-MM-dd"

Solution:

Unified configuration in configuration file

spring.jackson.time-zone=GMT+8
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss

4. Postman requests again and the conversion is successful

[Solved] Springboot test class injection bean is null Error: java.lang.NullPointerException…

When the springboot test class injects a NullPointerException object:

Normally, the test class add @springboottest can be tested normally

However, the value of classes in @ springboottest (classes = bootapplication. Class) can inject properties normally only after the class is started. That is, bootapplication is the springboot startup class

@RunWith(SpringRunner.class)

@SpringBootTest(classes = GrouptwoApplication.class)

Spring Error: ‘artifactId‘ with value ‘xxxx‘ does not match a valid id pattern.

Error: ‘artifactid’ with value ‘XXXX’ does not match a valid ID pattern.

Notes:

Error reason: POM file is in GAV format, UN-English characters or spaces are not allowed. Just use underscores, numbers and letters to change the artifactid attribute value to the required form .1 <artifactId> 2020_11_15

[Solved] The swagger UI dependency is introduced into spring boot Error

problem

Description:

Parameter 0 of method linkDiscoverers in org.springframework.hateoas.config.HateoasConfiguration required a single bean, but 3 were found:
	- relProviderPluginRegistry: defined by method 'relProviderPluginRegistry' in class path resource [org/springframework/hateoas/config/HateoasConfiguration.class]
	- linkDiscovererRegistry: defined in null
	- entityLinksPluginRegistry: defined by method 'entityLinksPluginRegistry' in class path resource [org/springframework/hateoas/config/WebMvcEntityLinksConfiguration.class]

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

This is because the dependent version is too old. The spring boot of version 2.5.6 is used, and the swagger of version 2.2 is too old.

The solution is to update the swagger dependency or reduce the spring boot version.

Error in the first line of pom.xml when importing springboot project

During the integration of Chen Jie report and springboot project, it was found that the first line of pom.xml reported an error after the springboot project was imported into eclipse. The following information was viewed on the Internet. The solutions are as follows:

1. Find the properties node in pom.xml file

2. Add & lt; under the properties node; maven-jar-plugin.version> 3.0.0

3. Right click eclipse — Maven — udate project

[Solved] Springtest error: java.lang.nosuchmethoderror

Complete error reporting information:

"C:\Program Files\Java\jdk1.8.0_301\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\lib\idea_rt.jar=53174:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\plugins\junit\lib\junit5-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\plugins\junit\lib\junit-rt.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\rt.jar;C:\Users\Cloud9\IdeaProjects\EveryThing-Framework\target\test-classes;C:\Users\Cloud9\IdeaProjects\EveryThing-Framework\target\classes;D:\Maven Local Repository\org\apache\curator\curator-framework\5.2.0\curator-framework-5.2.0.jar;D:\Maven Local Repository\org\apache\curator\curator-client\5.2.0\curator-client-5.2.0.jar;D:\Maven Local Repository\org\apache\zookeeper\zookeeper\3.6.3\zookeeper-3.6.3.jar;D:\Maven Local Repository\org\apache\zookeeper\zookeeper-jute\3.6.3\zookeeper-jute-3.6.3.jar;D:\Maven Local Repository\org\apache\yetus\audience-annotations\0.5.0\audience-annotations-0.5.0.jar;D:\Maven Local Repository\io\netty\netty-handler\4.1.63.Final\netty-handler-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-common\4.1.63.Final\netty-common-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-resolver\4.1.63.Final\netty-resolver-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-buffer\4.1.63.Final\netty-buffer-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-transport\4.1.63.Final\netty-transport-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-codec\4.1.63.Final\netty-codec-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-transport-native-epoll\4.1.63.Final\netty-transport-native-epoll-4.1.63.Final.jar;D:\Maven Local Repository\io\netty\netty-transport-native-unix-common\4.1.63.Final\netty-transport-native-unix-common-4.1.63.Final.jar;D:\Maven Local Repository\org\apache\curator\curator-recipes\5.2.0\curator-recipes-5.2.0.jar;D:\Maven Local Repository\commons-io\commons-io\2.11.0\commons-io-2.11.0.jar;D:\Maven Local Repository\commons-beanutils\commons-beanutils\1.7.0\commons-beanutils-1.7.0.jar;D:\Maven Local Repository\commons-logging\commons-logging\1.0.3\commons-logging-1.0.3.jar;D:\Maven Local Repository\org\javassist\javassist\3.26.0-GA\javassist-3.26.0-GA.jar;D:\Maven Local Repository\com\alibaba\fastjson\1.2.78\fastjson-1.2.78.jar;D:\Maven Local Repository\javax\servlet\javax.servlet-api\4.0.1\javax.servlet-api-4.0.1.jar;D:\Maven Local Repository\javax\servlet\jstl\1.2\jstl-1.2.jar;D:\Maven Local Repository\javax\servlet\jsp\javax.servlet.jsp-api\2.3.3\javax.servlet.jsp-api-2.3.3.jar;D:\Maven Local Repository\org\reflections\reflections\0.9.11\reflections-0.9.11.jar;D:\Maven Local Repository\com\google\guava\guava\20.0\guava-20.0.jar;D:\Maven Local Repository\mysql\mysql-connector-java\8.0.25\mysql-connector-java-8.0.25.jar;D:\Maven Local Repository\com\google\protobuf\protobuf-java\3.11.4\protobuf-java-3.11.4.jar;D:\Maven Local Repository\io\jsonwebtoken\jjwt\0.9.1\jjwt-0.9.1.jar;D:\Maven Local Repository\com\fasterxml\jackson\core\jackson-databind\2.9.6\jackson-databind-2.9.6.jar;D:\Maven Local Repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;D:\Maven Local Repository\com\fasterxml\jackson\core\jackson-core\2.9.6\jackson-core-2.9.6.jar;D:\Maven Local Repository\org\apache\httpcomponents\httpclient\4.5.13\httpclient-4.5.13.jar;D:\Maven Local Repository\org\apache\httpcomponents\httpcore\4.4.13\httpcore-4.4.13.jar;D:\Maven Local Repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;D:\Maven Local Repository\org\apache\httpcomponents\httpmime\4.5.13\httpmime-4.5.13.jar;D:\Maven Local Repository\junit\junit\4.12\junit-4.12.jar;D:\Maven Local Repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\Maven Local Repository\org\slf4j\slf4j-api\1.7.32\slf4j-api-1.7.32.jar;D:\Maven Local Repository\org\slf4j\slf4j-log4j12\1.7.32\slf4j-log4j12-1.7.32.jar;D:\Maven Local Repository\log4j\log4j\1.2.17\log4j-1.2.17.jar;D:\Maven Local Repository\cglib\cglib\2.2.2\cglib-2.2.2.jar;D:\Maven Local Repository\asm\asm\3.3.1\asm-3.3.1.jar;D:\Maven Local Repository\org\apache\poi\poi\5.0.0\poi-5.0.0.jar;D:\Maven Local Repository\org\slf4j\jcl-over-slf4j\1.7.30\jcl-over-slf4j-1.7.30.jar;D:\Maven Local Repository\org\apache\commons\commons-collections4\4.4\commons-collections4-4.4.jar;D:\Maven Local Repository\org\apache\commons\commons-math3\3.6.1\commons-math3-3.6.1.jar;D:\Maven Local Repository\com\zaxxer\SparseBitSet\1.2\SparseBitSet-1.2.jar;D:\Maven Local Repository\org\apache\poi\poi-ooxml\5.0.0\poi-ooxml-5.0.0.jar;D:\Maven Local Repository\org\apache\poi\poi-ooxml-lite\5.0.0\poi-ooxml-lite-5.0.0.jar;D:\Maven Local Repository\org\apache\xmlbeans\xmlbeans\4.0.0\xmlbeans-4.0.0.jar;D:\Maven Local Repository\org\apache\commons\commons-compress\1.20\commons-compress-1.20.jar;D:\Maven Local Repository\com\github\virtuald\curvesapi\1.06\curvesapi-1.06.jar;D:\Maven Local Repository\org\bouncycastle\bcpkix-jdk15on\1.68\bcpkix-jdk15on-1.68.jar;D:\Maven Local Repository\org\bouncycastle\bcprov-jdk15on\1.68\bcprov-jdk15on-1.68.jar;D:\Maven Local Repository\org\apache\santuario\xmlsec\2.2.1\xmlsec-2.2.1.jar;D:\Maven Local Repository\com\fasterxml\woodstox\woodstox-core\5.2.1\woodstox-core-5.2.1.jar;D:\Maven Local Repository\org\codehaus\woodstox\stax2-api\4.2\stax2-api-4.2.jar;D:\Maven Local Repository\jakarta\xml\bind\jakarta.xml.bind-api\2.3.2\jakarta.xml.bind-api-2.3.2.jar;D:\Maven Local Repository\jakarta\activation\jakarta.activation-api\1.2.1\jakarta.activation-api-1.2.1.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-all\1.13\batik-all-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-anim\1.13\batik-anim-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-shared-resources\1.13\batik-shared-resources-1.13.jar;D:\Maven Local Repository\xml-apis\xml-apis-ext\1.3.04\xml-apis-ext-1.3.04.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-awt-util\1.13\batik-awt-util-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\xmlgraphics-commons\2.4\xmlgraphics-commons-2.4.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-bridge\1.13\batik-bridge-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-codec\1.13\batik-codec-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-constants\1.13\batik-constants-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-css\1.13\batik-css-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-dom\1.13\batik-dom-1.13.jar;D:\Maven Local Repository\xalan\xalan\2.7.2\xalan-2.7.2.jar;D:\Maven Local Repository\xalan\serializer\2.7.2\serializer-2.7.2.jar;D:\Maven Local Repository\xml-apis\xml-apis\1.4.01\xml-apis-1.4.01.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-ext\1.13\batik-ext-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-extension\1.13\batik-extension-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-gui-util\1.13\batik-gui-util-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-gvt\1.13\batik-gvt-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-i18n\1.13\batik-i18n-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-parser\1.13\batik-parser-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-rasterizer-ext\1.13\batik-rasterizer-ext-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-rasterizer\1.13\batik-rasterizer-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-script\1.13\batik-script-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-slideshow\1.13\batik-slideshow-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-squiggle-ext\1.13\batik-squiggle-ext-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-squiggle\1.13\batik-squiggle-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-svg-dom\1.13\batik-svg-dom-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-svgbrowser\1.13\batik-svgbrowser-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-svggen\1.13\batik-svggen-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-svgpp\1.13\batik-svgpp-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-svgrasterizer\1.13\batik-svgrasterizer-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-swing\1.13\batik-swing-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-transcoder\1.13\batik-transcoder-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-util\1.13\batik-util-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-ttf2svg\1.13\batik-ttf2svg-1.13.jar;D:\Maven Local Repository\org\apache\xmlgraphics\batik-xml\1.13\batik-xml-1.13.jar;D:\Maven Local Repository\de\rototor\pdfbox\graphics2d\0.30\graphics2d-0.30.jar;D:\Maven Local Repository\org\apache\pdfbox\pdfbox\2.0.22\pdfbox-2.0.22.jar;D:\Maven Local Repository\org\apache\pdfbox\fontbox\2.0.22\fontbox-2.0.22.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch\7.15.1\elasticsearch-7.15.1.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch-core\7.15.1\elasticsearch-core-7.15.1.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch-secure-sm\7.15.1\elasticsearch-secure-sm-7.15.1.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch-x-content\7.15.1\elasticsearch-x-content-7.15.1.jar;D:\Maven Local Repository\org\yaml\snakeyaml\1.26\snakeyaml-1.26.jar;D:\Maven Local Repository\com\fasterxml\jackson\dataformat\jackson-dataformat-smile\2.10.4\jackson-dataformat-smile-2.10.4.jar;D:\Maven Local Repository\com\fasterxml\jackson\dataformat\jackson-dataformat-yaml\2.10.4\jackson-dataformat-yaml-2.10.4.jar;D:\Maven Local Repository\com\fasterxml\jackson\dataformat\jackson-dataformat-cbor\2.10.4\jackson-dataformat-cbor-2.10.4.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch-geo\7.15.1\elasticsearch-geo-7.15.1.jar;D:\Maven Local Repository\org\apache\lucene\lucene-core\8.9.0\lucene-core-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-analyzers-common\8.9.0\lucene-analyzers-common-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-backward-codecs\8.9.0\lucene-backward-codecs-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-grouping\8.9.0\lucene-grouping-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-highlighter\8.9.0\lucene-highlighter-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-join\8.9.0\lucene-join-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-memory\8.9.0\lucene-memory-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-misc\8.9.0\lucene-misc-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-queries\8.9.0\lucene-queries-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-queryparser\8.9.0\lucene-queryparser-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-sandbox\8.9.0\lucene-sandbox-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-spatial-extras\8.9.0\lucene-spatial-extras-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-spatial3d\8.9.0\lucene-spatial3d-8.9.0.jar;D:\Maven Local Repository\org\apache\lucene\lucene-suggest\8.9.0\lucene-suggest-8.9.0.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch-cli\7.15.1\elasticsearch-cli-7.15.1.jar;D:\Maven Local Repository\net\sf\jopt-simple\jopt-simple\5.0.2\jopt-simple-5.0.2.jar;D:\Maven Local Repository\com\carrotsearch\hppc\0.8.1\hppc-0.8.1.jar;D:\Maven Local Repository\org\lz4\lz4-java\1.8.0\lz4-java-1.8.0.jar;D:\Maven Local Repository\joda-time\joda-time\2.10.10\joda-time-2.10.10.jar;D:\Maven Local Repository\com\tdunning\t-digest\3.2\t-digest-3.2.jar;D:\Maven Local Repository\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;D:\Maven Local Repository\org\apache\logging\log4j\log4j-api\2.11.1\log4j-api-2.11.1.jar;D:\Maven Local Repository\org\elasticsearch\jna\5.7.0-1\jna-5.7.0-1.jar;D:\Maven Local Repository\org\elasticsearch\elasticsearch-plugin-classloader\7.15.1\elasticsearch-plugin-classloader-7.15.1.jar;D:\Maven Local Repository\org\apache\activemq\activemq-all\5.16.3\activemq-all-5.16.3.jar;D:\Maven Local Repository\org\springframework\spring-core\5.2.18.RELEASE\spring-core-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-jcl\5.2.18.RELEASE\spring-jcl-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-web\5.2.18.RELEASE\spring-web-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-beans\5.2.18.RELEASE\spring-beans-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-oxm\5.2.18.RELEASE\spring-oxm-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-tx\5.2.18.RELEASE\spring-tx-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-jdbc\5.2.18.RELEASE\spring-jdbc-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-webmvc\5.2.18.RELEASE\spring-webmvc-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-context\5.2.18.RELEASE\spring-context-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-expression\5.2.18.RELEASE\spring-expression-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-aop\5.2.18.RELEASE\spring-aop-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-context-support\5.2.18.RELEASE\spring-context-support-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-test\5.2.18.RELEASE\spring-test-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-jms\5.2.18.RELEASE\spring-jms-5.2.18.RELEASE.jar;D:\Maven Local Repository\org\springframework\spring-messaging\5.2.18.RELEASE\spring-messaging-5.2.18.RELEASE.jar;D:\Maven Local Repository\javax\jms\javax.jms-api\2.0.1\javax.jms-api-2.0.1.jar;D:\Maven Local Repository\org\apache\xbean\xbean-spring\3.7\xbean-spring-3.7.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 cn.cloud9.test.activemq.springactivemq.SpringActiveMqConsumer,springActiveMqConsume
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/Maven%20Local%20Repository/org/slf4j/slf4j-log4j12/1.7.32/slf4j-log4j12-1.7.32.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/Maven%20Local%20Repository/org/apache/activemq/activemq-all/5.16.3/activemq-all-5.16.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
[2021-11-02 08:14:25 上午]:DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:139)SpringJUnit4ClassRunner constructor called with [class cn.cloud9.test.activemq.springactivemq.SpringActiveMqConsumer]
[2021-11-02 08:14:25 上午]:DEBUG org.springframework.test.context.BootstrapUtils.createCacheAwareContextLoaderDelegate(BootstrapUtils.java:96)Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
[2021-11-02 08:14:25 上午]:DEBUG org.springframework.test.context.BootstrapUtils.createBootstrapContext(BootstrapUtils.java:79)Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
[2021-11-02 08:14:25 上午]:DEBUG org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:132)Instantiating TestContextBootstrapper for test class [cn.cloud9.test.activemq.springactivemq.SpringActiveMqConsumer] from class [org.springframework.test.context.support.DefaultTestContextBootstrapper]

java.lang.NoSuchMethodError: org.springframework.util.Assert.notNull(Ljava/lang/Object;Ljava/util/function/Supplier;)V

    at org.springframework.test.context.support.ContextLoaderUtils.resolveContextConfigurationAttributes(ContextLoaderUtils.java:244)
    at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:295)
    at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildTestContext(AbstractTestContextBootstrapper.java:108)
    at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:137)
    at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:122)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:151)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:142)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)


Process finished with exit code -1

The problem appears in the annotation @ runwith using the spring test component

package cn.cloud9.test.activemq.springactivemq;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations = {"classpath:ActiveMQ-Consumer.xml"}) 
public class SpringActiveMqConsumer {

    @Test
    public void springActiveMqConsume() throws Exception {
        // ApplicationContext ac = new ClassPathXmlApplicationContext("ActiveMQ-Consumer.xml");
        System.in.read();
    }
}

All spring component configuration versions:

<spring-version>5.2.18.RELEASE</spring-version>

JUnit beta:

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

The solution is to set a separate version for springtest:

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <!--<version>${spring-version}</version>-->
            <version>4.1.6.RELEASE</version>
        </dependency>

 

Spring: How to Solve Global exception @restcontrolleradvice

@Restcontrolleradvice is a composite annotation

@ControllerAdvice

@ResponseBody

import org.springframework.web.bind.annotation.RestControllerAdvice;

Function: enhance the controller, match the two, and often handle global exceptions

@Controlleradvice works on classes in three ways

Global exception handling: @ModelAttribute

Global data binding: @ModelAttribute

Global data preprocessing: @InitBinder

Global exception handling

@RestControllerAdvice
public class GlobalExceptionDeal {
	@ExceptionHandler(NullPointerException.class)
	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
	public ResponseBean dealNullPointerException() {
		ResponseBean responseBean = new ResponseBean(500,"Server exception - null pointer exception");
		return responseBean;
	}
	@ExceptionHandler(Exception.class)
	@ResponseStatus(value=HttpStatus.INTERNAL_SERVER_ERROR)
	public ResponseBean dealUnexpectedException(){
		ResponseBean responseBean=new ResponseBean(505,"Server exception - unknown error");
		return responseBean;
	}
}

Spring Error: _net.sf.jsqlparser.statement.select.PlainSelect.getGroupByColumnReferences()Ljava/util/List;

I reported this error during the list interface test. After searching online, I found that the reason for this error is that the project POM relies on PageHelper and mybatis plus at the same time, resulting in the jar conflict of jsqlparser.

The code uses a method in one version, but the request uses another version, which does not have the method in the other version. Therefore, you can delete the jsqlparser dependency under PageHelper in the POM file

Normal requests can be made after deletion.

[Solved] Spring introduces the properties variable Error: org.springframework.beans.TypeMismatchException…

Configure the data source through the properties configuration file. The code is as follows:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="order" value="3" />
        <property name="ignoreUnresolvablePlaceholders" value="true" />
        <property name="locations">
            <list>
                <value>classpath:config/db.properties</value>
                <!-- Note the path to write, the above write method to add classpath, path before can not have /, the following write method properties file to be in the WEB-INF directory, path before to have/
                <value>/WEB-INF/test.properties</value> -->
            </list>
        </property>
    </bean>
    
    <bean id="dataSource" name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <property name="driverClassName" value="${db.jdbc.driverClassName}" />
        <property name="url" value="${db.jdbc.url}" />
        <property name="username" value="${db.jdbc.username}" />
        <property name="password" value="${db.jdbc.password}" />
        <property name="initialSize" value="${db.initialSize}"/>
        <property name="maxActive" value="${db.maxActive}"/>
        <property name="maxWait" value="${db.maxWait}" />
        <property name="poolPreparedStatements" value="true" />
        <property name="defaultAutoCommit" value="true" />
        <property name="maxIdle" value="${db.maxIdle}" />
        <property name="minIdle" value="${db.minIdle}" />
        <property name="timeBetweenEvictionRunsMillis" value="${db.timeBetweenEvictionRunsMillis}" />
        <property name="minEvictableIdleTimeMillis" value="${db.minEvictableIdleTimeMillis}" />
        <property name="validationQuery" value="select 1 from dual"/>
        <property name="testWhileIdle" value="true"/>
        <property name="testOnBorrow" value="true"/>
        <property name="testOnReturn" value="false"/>
        <property name="filters" value="stat"/>
    </bean>

Project startup error:

org.springframework.beans.TypeMismatchException…

java.sql.SQLException: ${db.jdbc.driverClassName}

After consulting the data, it is found that this configuration is caused by:

<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.xiaomu.**.dao" />
    <property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>

Reason:

Mappercannerconfigurer has customized the initialization interface of the bean. During its initialization, the placeholder has not been initialized, resulting in an error when the properties value has not been injected

Solution:

Mapperscannerconfigurer has two options when injecting sqlsessionfactory. One is to directly inject sqlsessionfactory objects during spring configuration, and the other is to inject beans through names

So < property name=”sqlSessionFactory” ref=”sqlSessionFactory” /> Change to < property name=”sqlSessionFactoryBeanName” value=”mybatisSqlSessionFactory” /> Note that after the change, the original sqlsessionfactory name cannot be used for the value value, because it is injected through the name, so using sqlsessionfactory will still report an error

Note: sqlsessionfactorybeanname is a non mandatory label and can be configured without a single data source

Description:

Mappercannerconfigurer is similar to the mappers tag in that it scans mappers to determine the mapping relationship. The mapper configuration form is:

<mappers>
    <!-- sql file configuration way one: specify the file path location, sql.xml file namespace can be directly with dao name, note that at this time sql.xml file to be in the resource directory -->
    <! -- <mapper resource="mybatis/sqlmap/user/brokerinfoMapper.xml"/> -->
    <! -- sql file configuration way two: sql file and dao interface in the same directory, only need to configure the sql.xml file and the interface package path , but the sql.xml file and the interface path are in the same directory.
But the namespace of sql.xml should be the full path of the dao interface-->
    <!-- <package name="com.test.web.dao"/> -->
</mappers>