Tag Archives: spring boot

[Solved] ‘build.plugins.plugin.version‘ for org.springframework.boot:spring-boot-maven-plugin is missing.


Some problems were encountered while building the effective model for org.example:cloud2021:pom:1.0-SNAPSHOT
'build.plugins.plugin.version' for org.springframework.boot:spring-boot-maven-plugin is missing. @ line 88, column 15
It is highly recommended to fix these problems because they threaten the stability of your build.
For this reason, future Maven versions might no longer support building such malformed projects.

Use idea to create spring boot project when some of the pits encountered, record

In the pom.xml file, the “spring boot Maven plugin” is red, and not found is displayed

Let’s look at a translation first

Go to line 87 and find the problem configuration

<plugin>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

I also saw some other people’s solutions on the Internet. Finally, I successfully solved them by specifying the version of spring boot Maven plugin. It is revised as follows:

<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<version>2.2.6.RELEASE</version>
</plugin>

solve!!!

[Solved] Failed to resolve org.junit.platform:junit-platform-launcher:1.7.2

For springboot project, when using applicationtests to test, the following error will be prompted:

11:47 am  Error running ‘ShiroDemoApplicationTests.contextLoads’: Failed to resolve org.junit. platform:junit-platform-launcher :1.7.2

Reason: IntelliJ idea version and JUnit version do not match

solve:

1. Add the following dependencies to the pom.xml file of the project:

<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <scope>test</scope>
</dependency>

2. It is more troublesome to adjust the two versions to match. The first method is recommended.

Springboot running shows application run failed [How to Solve]

Error:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-06-28 14:27:13.827 ERROR 7512 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

Background

It’s time to review. The teacher asked me to write a springboot project, but I couldn’t run it. Running application shows that application cannot be run
some errors were encountered in the process. I searched Baidu, and the result is as follows:
in the annotation of application, there is @ springbootapplication , which should be replaced by @ springbootapplication (exclude = datasourceautoconfiguration. Class) , but the result still doesn’t work.

Exclude to exclude such autoconfig, that is, to prohibit springboot from automatically injecting data source configuration. In this case, the automatic injection of mybits is excluded. As a result, there is a problem in the mapper layer.

Let the teacher have a look today. There is something wrong with the YML file.

Forget to write spring keywords, which I don’t understand.

server:
  port: 5050 # tomcat port
  servlet:
    context-path: /UserModel

spring:# I forgot to write it here, so that datesource belongs to the server
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/1202?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf-8
    username: root
    password: root

An error occurred while accessing the controller

The error reported is the same as this:

would dispatch back to the current handler URL [/UserModel/queryUserById] 

The difference between @Controller and @RestController is actually confusing
@Controller, @RestController?
Forgot the difference between get and post

Written by.
http://localhost:5050/UserModel/deleteUserByIds?ids=3,4

[Solved] Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerExcepti

 

1、 Background description

Project architecture: spring boot (v2.0.0. Release) + mybatis plus (v3.1.1)

Today, I developed a new function on an old project (running normally). Before adding new functions, the project started and ran normally. As a result, after the development, the project couldn’t start and the background didn’t report any error information. The key is that I didn’t even have a log. For a moment, I couldn’t start it.

2、 Cause analysis

According to the situation analysis, the project can’t be started. Thinking that there must be a problem in starting, a try… Catch… Block is added to the line of starting the project in the starting class (that is, the following code plus).

SpringApplication.run(DailyApplication.class, args);

See if there is an error log.

@Slf4j
@EnableScheduling
@EnableFeignClients(basePackages = "com.iot")
@SpringBootApplication(scanBasePackages={"com.iot"})
@MapperScan({"com.iot.daily.*.dao"})
public class DailyApplication implements ApplicationRunner {

    public static void main(String[] args) {
        try {
            SpringApplication.run(DailyApplication.class, args);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("error: ============== ", e);
        }
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("The daily report system was successfully launched!......");
    }
}

Start the project, and then, as expected, the console displays the error log with the following error message:

Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat

The specific error information will be supplemented later, but now it can’t be reproduced.

3、 Solutions

Here is my project solution, very simple, Maven clean once, and then restart.

end!

[Solved] The version of springcloud must support the current version of springboot, otherwise the startup project will report an error: error starting ApplicationContext

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2021-06-26 15:42:31.976 ERROR 208496 — [           main] o.s.b.d.LoggingFailureAnalysisReporter   :
***************************
APPLICATION FAILED TO START
***************************
Description:
Your project setup is incompatible with our requirements due to following reasons:
– Spring Boot [2.3.0.RELEASE] is not compatible with this Spring Cloud release train

Action:
Consider applying the following actions:
– Change Spring Boot version to one of the following versions [2.4.x, 2.5.x] .
You can find the latest Spring Boot versions here [https://spring.io/projects/spring-boot#learn].
If you want to learn more about the Spring Cloud Release train compatibility, you can visit this page [https://spring.io/projects/spring-cloud#overview] and check the [Release Trains] section.
If you want to disable this check, just set the property [spring.cloud.compatibility-verifier.enabled=false]

Disconnected from the target VM, address: ‘127.0.0.1:10542’, transport: ‘socket’
Process finished with exit code 1
Follow the prompts to upgrade the SpringBoot version or lower the SpringCloud version to make both support each other.The reason for the error is that when I followed the online tutorials to write the code, the SpringBoot version of the pom in the project automatically generated by IDEA was aligned with the tutorials and the project started with an error. In order to follow less errors, I downgraded the version of SpringCloud to be consistent with the one in the tutorial.

2020.03

Amend to read

Hoxton.SR8

Restart project OK

Application failed to start

Error recurrence

Cause: the database related auto configuration library was imported, but the database was not configured in the configuration file.
solution: just exclude the database and add the following on the startup class annotation:

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

[Solved] Description: Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded

Description:
Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
My database configuration file is application.properties. after reading it seems to be unreadable, I recreate the application.yml file again, just copy the configuration file to this side yml. restart it and it’s fine.

server:
  port: 8080
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/springcloud?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=UTC
    username: root
    password: 123456

I don’t know why.

How to Solve Errors encountered by maven

Could not transfer artifact
org.apache.maven.surefire:surefire-junit-platform:pom:2.22.2 from/to
alimaven (http://maven.aliyun.com/nexus/content/groups/public/):
java.lang.RuntimeException: Unexpected error:
java.security.InvalidAlgorithmParameterException: the trustAnchors
parameter must be non-empty

Solution:

Just load this dependency

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>

Frequent log swiping after Nacos client starts [How to Solve]

# 1, according to the heartbeat log, locate the package name of the log output
c.a.n.client.config.impl.ClientWorker : get changedGroupKeys:[]

# 2. Search the package path where ClientWorker is located in IDEA  
package com.alibaba.nacos.client.config.impl;

# 3. Set the package path logging to ERROR or WARN in any configuration file format
# Nacos registry client heartbeat logging is disabled get changedGroupKeys:[] 
logging:
  level:
    com.alibaba.nacos.client.config.impl: WARN
  
# 4. If it is Spring Cloud Gateway then you need to configure it as logging:
  level:
    com.alibaba.nacos.client.*: WARN    

IDEA: How to Add @Data plug-in

In the code, there is @data annotation in the bean class. Normally, a series of template methods such as getter/setter/tostring() will be automatically added to the compiled class. However, in practice, after the subclass inherits the bean class, the getter/setter method cannot be used by default.

Why? This is because plug-in support needs to be added to IDEA.

Settings—> Plugins, click marketplace, input Lombok, install and restart idea.


</ div>

Springboot startup error could not resolve placeholder XXX

An error was reported when launching the springboot project today

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 
'spring.datasource.druid.initialSize' in value "${spring.datasource.druid.initialSize}"

First, confirm whether the field exists in the configuration file and whether the field name is written correctly. If it is confirmed that there is no error, check whether the configuration file is referenced. Generally, we will configure different configuration files in different environments, so we need to specify which configuration file to use in application.yml

spring:
  profiles: 
    active: druid

During the startup process, which file is used will be output. Note that if there is no output, it means that it has no effect

if you check the above, you can try build – & gt; Rebuild project try to rebuild and I succeed.

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