springboot service层注解失败

springboot 项目编译报错 
报错信息如下

Description:

Field blogArticleService in com.xgc.controller.BlogArticleController required a bean of type 'com.xgc.service.IBlogArticleService' that could not be found.


Action:

Consider defining a bean of type 'com.xgc.service.IBlogArticleService' in your configuration.


Process finished with exit code 1

springboot启动文件

package com.xgc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import tk.mybatis.spring.annotation.MapperScan;

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
//@MapperScan({"com.xgc.service"})
@MapperScan("com.xgc.mapper")
@ComponentScan(basePackages={"com.xgc"})
//@ComponentScan(basePackages={"com.xgc.mapper","com.xgc.service.impl","com.xgc.service"})
//@EnableSwagger2
public class XgcApplication {

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

启动文件模块项目Web的maven配置


    
        com.xgc
        xgc-common
        0.0.1-SNAPSHOT
    
    
        com.xgc
        xgc-user-center-api
        0.0.1-SNAPSHOT
    
    
        com.xgc
        xgc-blog-center-api
        0.0.1-SNAPSHOT
    
    
    
        org.projectlombok
        lombok
        true
    
    
        org.springframework.boot
        spring-boot-starter-web
    
    
        org.springframework.boot
        spring-boot-starter-thymeleaf
    
    
    
        com.alibaba
        druid-spring-boot-starter
        1.1.9
    
    
        mysql
        mysql-connector-java
        5.1.35
    
    
    
        com.github.pagehelper
        pagehelper-spring-boot-starter
        1.2.3
        
            
                org.mybatis.spring.boot
                mybatis-spring-boot-starter
            
            
                org.springframework.boot
                spring-boot-starter
            
        
    

项目结构

springboot service层注解失败_第1张图片

启动失败原因 解释

    xgc-web 是我项目的启动 APP所在模块

    xgc-blog  xgc-user 是我的业务模块

    api是业务对外的开放的service接口,center是业务的实现类

     ①、在xgc-web模块中引用了api模块,没有引入center模块,在启动项目时,项目没有扫描到center里的是实现类,无法实现自动注入service bean,顾报了没有找bean的错误。

    ②  xml映射文件没有扫描到。需要在maven中pom.xml配置


        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
        
            
                src/main/java
                
                    **/*.xml
                
                false
            
            
                src/main/resources
                
                    **/*.xml
                
                false
            
        
    

注意包的创建,使用package,不要使用文件夹(directory)创建包。使用文件夹,扫描的时候没有扫描到类

项目涉及的知识有待巩固:

   1、maven 多模块的使用,及jar的运用。因做项目时想做一个公共的jar供其他模块调用,没有实现成功。

    2、此项目是为了延伸向dubbo的项目,顾模块之间的依赖关系没有做好,后期先实现springboot项目,在向dubbo进发。

bug尴尬了一个星期,谨为记录自己的点点滴滴。写得不好,欢迎来怼。谢谢

你可能感兴趣的:(spring家族)