springboot stepped out of the pit pit remember

April 15 to April 17 I have been reconstructed from the complete set to eclipse the IDEA, springboot me the most headaches is its version of the problem, because each corresponds to the version dependencies can go wrong, how to share here successful transplant written eclipse of springboot to IDEA, the relatively simple steps I have not explained in detail here, talk about some of the places difficult to find the problem I encountered
ps: just specific to my project and my personal level, great God Hey do not spray

springboot-mybatis integration pit

  • Appears under the incorrect please see the start classes: whether XXXApplication Scan to mapper mapping file, and the idea is not the same statement eclipse, eclipse can run through here, the idea does not work
        ***************************
        APPLICATION FAILED TO START
        ***************************

        Description:

        Field chapterDao in cn.yixue.service.ChapterServiceImp required a bean of type 'cn.yixue.dao.ChapterMapper' that could not be found.

        The injection point has the following annotations:
            - @org.springframework.beans.factory.annotation.Autowired(required=true)


        Action:

        Consider defining a bean of type 'cn.yixue.dao.ChapterMapper' in your configuration.


        以上提取出有用的信息:required a bean of type 'xxxx' that could not be found.
        
        代表bean没注入,从bean注入寻找方向,有的人会说我用@Autowired之类的种种,但没扫到,好吧~

Solution:

  1. The corresponding mapper class labeled @Mapper added to make labels in accordance with the mapper springboot injection
@Mapper
public interface ChapterMapper {
    ......
}
  1. Start class plus @MapperScan(value = "cn.yixue.video.dao")package after the value must correspond to the corresponding place mapper class, such as my mapper in the dao, it iscn.yixue.video.dao
@SpringBootApplication
@MapperScan(value = "cn.yixue.video.dao")
@EnableDiscoveryClient
public class YixueVideoApplication {

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

}
  1. Spring Boot project contains Mybatis, the run after beating Jar package, reported the following error:
***************************
APPLICATION FAILED TO START
***************************

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).

Many online solutions for each person is different, I should be packed when not read my profile, you need to pom.xmladd inside resoursesdesignated under the configuration file, because the eclipse is to identify, Idea may not? I do not know, because it is a plus, because it seems I have not read the Idea application.propertiesor application.ymlfile, I would have accompanied a one-time, when we encounter this particular search again on the line, do not deliberately remember :

<build>
<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<resources>
    <resource>
        <directory>src/main/java</directory>
        <includes>
            <include>**/*.yml</include>
            <include>**/*.properties</include>
            <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <includes>
            <include>**/*.yml</include>
            <include>**/*.properties</include>
            <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
    </resource>
</resources>
</build>

springBoot-SpringCloud integration pit

  • When using the SpringCloud do service registration, Eclipse needs its own guide jar package dependencies and configuration version, Idea can re-direct the project to create Springboot introduced into mouse clicks, which I put a few pictures to explain:



After the last next direct finish ......

After pom.xml which will then automatically see Idea and you rely on the introduction of spring-boot-maven-pluginplug-in, plug-in version I suggest slightly lower, because boot is really a big change with version changes, I use

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

This is also a version of Internet search to find after a long time, as well as a 1.4.9.RELEASEcan, is to look after the Idea import SpringCloud-dependent version version, the wrong version is easy to report java.lang.AbstractMethodError: nullthis error I am looking for a long time, the reason also read a Gangster blog found, because Idea specific to your dependence is based on the version you choose to springboot, most people will not go to modify, which is why the eclipse is not easy being given due Idea easy, because the eclipse have to find their own .. .

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

My version is the parent <version>2.0.5.RELEASE</version>, big brother article also mentioned a difference 2.1.0 and 2.1.0 below, I recommend using a low, low will not be much difference, quite stable ...... I also used 1.5.9.RELEASE ...

  • After configuring eurekathe time of services provided by Idea versions have to be changed, the reason is because if you use ${spring-cloud.version}it, when the version number down to 2.1.0less time, some of the components of the package or 2.1.0it does not follow the parent version and cut down, that is parent the version is less than the version of the component, and this time it will go wrong
    when instead Finchley.RELEASEtime-dependent component of the parent version will follow and cut down
<properties>
    <java.version>1.8</java.version>
    <!-- 这是Idea给设的 -->
    <!--<spring-cloud.version>Greenwich.SR1</spring-cloud.version>-->
    <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Solve the pit when the static cross-domain resource

  • Before the eclipse static resources can be accessed through
@Autowired
private RestTemplate restTemplate;

Direct assembly, after being given to the Idea:

ERROR 31473 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field restTemplate in 'xxxxxx'
required a bean of type 'org.springframework.web.client.RestTemplate' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your configuration.

Solutions are as follows, it is the first by roughly @Bean assembly, and then ...:

@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
   // Do any additional configuration here
   return builder.build();
}
@Autowired
private RestTemplate restTemplate;

After not being given (to me for the wrong)

My pom.xml (project of xml)

My architecture

click me
Enclosed places pom.xml file below

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>cn.yixue</groupId>
    <artifactId>yixue</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <java.version>1.8</java.version>
        <lombok.version>1.14.8</lombok.version>
        <fastjson.version>1.2.31</fastjson.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.46</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>${fastjson.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.5.9.RELEASE</version>
                <configuration>
                    <!--该配置必须-->
                    <fork>true</fork>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <modules>
        <module>yixue-commom</module>
        <module>yixue-admin</module>
        <module>yixue-video</module>
    </modules>
</project>

This is some of the problems I encountered migration projects, listed below some of the chiefs of the blog, helped me a lot, appreciate it
if infringement, please contact me delete

Guess you like

Origin www.cnblogs.com/cxylff/p/10969375.html