Tag Archives: springBoot

Springboot project startup prompt error: (3, 37) Java: package org.mybatis.spring.annotation does not exist

#Error: (3, 37) Java: package org.mybatis.spring.annotation does not exist

Generally, there is no problem with the configuration when pulling items from GIT and running. This will be prompted when starting

Refactoring is also ineffective at this time. Most of them are caused by this problem

Open the settings and check the blue box as shown in the figure

Then start the OK solution

[Solved] Error reported when adding ojdbc6 to springboot

Generally, adding ojdbc6 database driver to springboot will report an error, and the dependency cannot be added. The reason is that the ojdbc6 database driver is charged and cannot be downloaded directly through Maven. You need to download ojdbc6.jar manually and add it to your own warehouse manually

The first step is to download the jar package of ojdbc6

https://mvnrepository.com/artifact/com.oracle/ojdbc6/11.2.0.3

Select jar to download it

Step 2 rename ojdbc6 the downloaded jar and put it in the directory of the C disk user

Step 3 open the CMD window from this directory

Execute command

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=ojdbc6.jar

Add it to your Maven

This indicates that the addition was successful

Step 4 go to your own warehouse to check

 

The jar package has been added

If you just add a dependency, you won’t report an error

		<dependency>
			<groupId>com.oracle</groupId>
			<artifactId>ojdbc6</artifactId>
			<version>11.2.0.3</version>
		</dependency>

The thymeleaf engine in springboot reports an error [Solved]

Error reported by thymeleaf:

An error happened during template parsing (template: “class path resource [templates/hello.html]”)] with root cause……

Each of the following is a single solution! Not a step

1. Clear your compiler cache! And restart

2. Clear the browser cache Ctrl + Shift + Del

3. Check the configuration file (. POM file): whether it contains dependencies. If not, please add it

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

4. In application. properties

#Set prefix and suffix
spring.thymeleaf.mode=HTML
spring.thymeleaf.suffix=.html
spring.thymeleaf.prefix=classpath:/templates/

5. Is it a coding problem? The code here refers to the code with errors, syntax, and other problems

 

Springboot startup error yamlexception/malformedinputexception input length = 1

Test springboot locally, and the startup error is as follows:

21:04:19.284 [restartedMain] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'
	at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:545)
......
Caused by: org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1
......
Caused by: java.nio.charset.MalformedInputException: Input length = 1
	......

Finally, it is found that the encoding problem of application.yml file is changed from GBK to UTF-8

Springboot always reports an error when importing JSP dependencies

Paste my own POM code first:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 4     <modelVersion>4.0.0</modelVersion>
 5     <parent>
 6         <groupId>org.springframework.boot</groupId>
 7         <artifactId>spring-boot-starter-parent</artifactId>
 8         <version>1.5.6.RELEASE</version>
 9         <relativePath/> <!-- lookup parent from repository -->
10     </parent>
11     <groupId>com.sblueice</groupId>
12     <artifactId>demo</artifactId>
13     <version>0.0.1-SNAPSHOT</version>
14     <packaging>war</packaging>
15     <name>demo</name>
16     <description>Demo project for Spring Boot</description>
17 
18     <properties>
19         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
21         <java.version>1.8</java.version>
22     </properties>
23 
24     <dependencies>
25         <dependency>
26             <groupId>org.springframework.boot</groupId>
27             <artifactId>spring-boot-starter-web</artifactId>
28         </dependency>
29         <dependency>
30             <groupId>javax.servlet</groupId>
31             <artifactId>javax.servlet-api</artifactId>
32             <scope>provided</scope>
33         </dependency>
34         
35          <!--sppourt jsp -->
36         <dependency>
37               <groupId>javax.servlet</groupId>
38               <artifactId>jstl</artifactId>
39               <version>1.2</version>
40         </dependency>
41 
42        <dependency>
43         <groupId>com.mchange</groupId>
44         <artifactId>c3p0</artifactId>
45         <version>0.9.5.2</version>
46     </dependency>
47         <!-- Setting it to provided will exclude the package when packaging, as it is not needed to be put into a standalone tomcat to run. -->
48         <dependency>
49             <groupId>org.springframework.boot</groupId>
50             <artifactId>spring-boot-starter-tomcat</artifactId>
51             <scope>provided</scope>
52         </dependency>
53         <dependency>
54             <groupId>org.springframework.boot</groupId>
55             <artifactId>spring-boot-starter-test</artifactId>
56             <scope>test</scope>
57         </dependency>
58         <dependency>
59             <groupId>org.springframework.boot</groupId>
60             <artifactId>spring-boot-devtools</artifactId>
61             <optional>true</optional>
62         </dependency>
63                 <dependency>
64             <groupId>org.springframework.boot</groupId>
65             <artifactId>spring-boot-starter-jdbc</artifactId>
66         </dependency>
67         <dependency>
68             <groupId>org.mybatis.spring.boot</groupId>
69             <artifactId>mybatis-spring-boot-starter</artifactId>
70             <version>1.3.2</version>
71         </dependency>
72         <dependency>
73             <groupId>mysql</groupId>
74             <artifactId>mysql-connector-java</artifactId>
75             <scope>runtime</scope>
76         </dependency>
77 
78     </dependencies>
79 
80     <build>
81         <plugins>
82             <plugin>
83                 <groupId>org.springframework.boot</groupId>
84                 <artifactId>spring-boot-maven-plugin</artifactId>
85             </plugin>
86            <plugin>
87                  <groupId>org.apache.maven.plugins</groupId>
88                  <artifactId>maven-compiler-plugin</artifactId>
89                  <version>3.1</version>
90                  <configuration>
91                      <source>1.8</source>     
92                      <target>1.8</target>     
93                  </configuration>
94            </plugin>
95         </plugins>
96     </build>
97 
98 </project>

 

Modification 1: first, the parent class depends on the version number, which is changed from 2.0.1 to 1.5.6 according to Baidu

  Modification 2: again, the error of importing JSP dependency: missing artifact org.apache.tomcat.embedded: Tomcat embedded Jasper: jar: 8.5.16

If you don’t add a JSP dependency, you can download the JSP file directly and report an error if you add it. Now I’m confused

Record it, there is a great God answer is more desirable

October 10, 2019 has been solved:

Finally, it was found that there was a problem with the version. It was tested from 1.5.6 to 2.0.3. It was found that there was no problem with the version 2.0.3, which proved that this version was suitable for my computer and my eclipse

Operating system: win10 64 bit
Eclipse: Version: 2019-09 R (4.13.0)
Maven should be 3.5.0

1. The following are the dependencies required by JSP :

    <!--servlet begin -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <scope>provided</scope>
    </dependency>
    <!--servlet end -->
    <!--jsp begin -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
    <!--jsp end -->
    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-jasper</artifactId>
      <scope>provided</scope>
    </dependency>

 

2. Add the prefix in application.yml

  spring:
    mvc:
      view:
        prefix: /WEB-INF/views
        suffix: .jsp

—-Encourage with you

[Solved] Springboot Error: invalid bound statement (not found)

1. Overview

An error is reported after springboot starts the web project

invalid bound statement (not found):xxx

2. Problem analysis

This is a very common exception. Error reporting usually includes the following situations:

2.1 syntax error

Mapper.xml does not correspond to Dao correctly

Java Dao interface

public void delete(@Param("id") String id);

Mapper.xml file corresponding to Java

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="xxx.xxx.xxx.xxDao">
    <!-- Delete -->
    <delete id="delete" parameterType="java.lang.String">
        DELETE FROM xxx WHERE id=#{id}
    </delete>
</mapper>

Check and confirm:

a) Whether the interface method name delete is consistent with the id = “delete” in XML

b) Whether the namespace = “XXX. XXX. XXX. Xxxdao” in the XML file is consistent with the path of the interface file (click whether to jump to the corresponding interface class)

 

c) Whether parametertype and resulttype (resultmap) are accurate

2.2 compilation error

Check whether the corresponding mapper.xml file exists under the project target \ classes \ path

If it does not exist, add it in pom.xml

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>**/*.properties</exclude>
                <exclude>**/*.xml</exclude>
            </excludes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

Recompile and the corresponding XML file will appear (if you want to copy the XML, properties and other configuration files under Src/main/Java to the classes directory, add the above configuration)

two point three   Configuration error

There is a problem with the configuration path when specifying the scan package (mybatis. Mapper locations = classpath *:/XX/XX/mapper/*. XML) in the configuration file

 

An error occurs when springboot sets the log level [How to Solve]

Configure the springboot log. The output level is info. An error is reported when running:

Caused by: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'logging.level' to java.util.Map<java.lang.String, java.lang.String>
    at org.springframework.boot.context.properties.bind.Binder.handleBindError(Binder.java:250)
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:226)
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:210)
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:166)
    at org.springframework.boot.context.logging.LoggingApplicationListener.setLogLevels(LoggingApplicationListener.java:307)
    at org.springframework.boot.context.logging.LoggingApplicationListener.initializeFinalLoggingLevels(LoggingApplicationListener.java:290)
    at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:238)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:200)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:173)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)

The application.yml file is configured as follows:

 

logging:
  pattern:
    console: "%d - %msg%n" #     Define the format of the log to be printed
# dateformat: # Set the log date format
# file: # Defines the log format for output to the log file
# config: # The location of the logging configuration file. For example, classpath:logback.xml.
  file: E:/sell/sell.log # Set the log file where the logs are saved
# max-history:
# max-size: # Set the maximum size of the log file # Set the log level
# path:/# location of the log file, e.g. /var/log
  register-shutdown-hook: false # Register a shutdown hook for the logging system when it is initialized.
  level: info

The reason is that the log level is configured incorrectly. It should be configured as

level:
    root: info

The reasons are as follows:

Find the logging log level configuration shown in the following figure in the official document. The official address is: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot -Features custom log levels

roughly means that we can use trace,   DEBUG,   INFO,   WARN,   ERROR,   FATAL,   perhaps   Off to specify the spring project log level. Its format is:
logging. Level. < logger-name>=< level>
therefore, we need to configure a logger name when configuring the log level, so we can specify a root or a package path as shown in the figure above. Configuring logging. Level. Root = warn means configuring the root logger, so the following configuration ideas are:
logging. Level. Root = warn
logging.level.org.springframework.web=DEBUG
The configuration of logging. Level. Org. Hibernate = error
is that org.springframework.web is the debug level, org.hibernate is the error level, and the log output level of other projects is warn

 

Springboot about the error report of findone() method in springdatajpa

Problem Description:

First, using the 1.11 version of spring data JPA, you can use the findone () method to query by ID

Then I used version 2.0.5 and found that the findone() method reported an error and could not be used to query by ID

When the findbyid (ID) is used for query and the page uses thymeleaf to receive the data from the controller, the page reception fails

Solution:

Use findById(id).get() to perform the query.

 

Springboot startup error start bean ‘eurekaautoserviceregistration’ NullPointerException

Solution reference: https://blog.csdn.net/hhj13978064496/article/details/82825365

 

I put Eureka’s dependent package at the bottom of the dependent package and start to report an error

As follows:

    <dependencies>



        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.0.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>2.0.6.RELEASE</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-oauth2 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
            <version>2.1.3.RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.security.oauth/spring-security-oauth2 -->
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.3.6.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>


        <!-- https://mvnrepository.com/artifact/javax/javaee-api -->
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>8.0</version>
            <scope>provided</scope>
        </dependency>


        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>

        <!-- eureka client -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>

 

Move Eureka to the top and start normally. It is speculated that Eureka is dependent

As follows:

 <dependencies>

        <!-- eureka client -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.0.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>2.0.6.RELEASE</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-oauth2 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
            <version>2.1.3.RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.security.oauth/spring-security-oauth2 -->
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.3.6.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>


        <!-- https://mvnrepository.com/artifact/javax/javaee-api -->
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>8.0</version>
            <scope>provided</scope>
        </dependency>


        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>

    </dependencies>

 

 

Thus, Maven dependencies are sequential