SPRINGBOOT2.X入门学习

SPRINGBOOT2.X微应用基础版

    • 环境说明
    • 工程结构
          • 主工程 : BZQ-4Spring-B2B2C
          • 消费者 : BZQ-B2B2C-ADDRESS-CONSUMER
          • 生产者:BZQ-B2B2C-ADDRESS-PROVIDER
          • 工具者: BZQ-B2B2C-COMMON
          • 基础API: BZQ-B2B2C-ADDRESS-API;
    • MAVEN配置
    • MaVEN配置说明
        • 依赖SPRING2工程:
    • SPRINGBOOT2配置说明
    • ZooKeeper server
    • SPRINGBOOT2项目启动
    • SPRINGBOOT2简单版本的启动类
        • Spring Boot 推荐目录结构
        • 控制层代码(controller)
        • 服务层代码(DUBBO)
    • DUBBO接口定义
    • 通用服务层代码
        • - 接口
        • - 实现类
    • SPRINGBOOT2持久层
        • - 接口
        • - MAPPER文件
    • MYBATIS说明
        • pom.xml文件中需要加入
        • - application-mybatis.yml
    • SPRINGBOOT2配置DUBBO
        • - 启动,要启动消费者、生产者哦
        • - 配置 pom.xml 文件中需要有:
        • 注册方
        • 调用方
    • 数据库
          • application-jdbc.yml
          • pom.xml
          • 表结构SQL
    • 常见异常
    • 小结

环境说明

IDE:Spring Tool Suite 4 。
JDK:1.8
spring boot版本:2.0.6.RELEASE
MAVEN:构建多工程
持久层: MYBATIS mybatis-spring-boot-starter 1.3.2

工程结构

通过MAVEN构建多工程:

主工程 : BZQ-4Spring-B2B2C
消费者 : BZQ-B2B2C-ADDRESS-CONSUMER
生产者:BZQ-B2B2C-ADDRESS-PROVIDER
工具者: BZQ-B2B2C-COMMON
基础API: BZQ-B2B2C-ADDRESS-API;

MAVEN配置

主工程 : BZQ-4Spring-B2B2C:



		4.0.0
	com.bzqb2b2c.address
	BZQ-B2B2C-ADDRESS-API
	1.0-SNAPSHOT
	jar
	
		UTF-8
		UTF-8
		1.8		 			
	

BZQ-B2B2C-ADDRESS-CONSUMER:



	4.0.0
	com.bzqb2b2c.address
	BZQ-B2B2C-ADDRESS-CONSUMER
	1.0-SNAPSHOT
	jar
    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.6.RELEASE
         
    
    BZQ-B2B2C-ADDRESS-CONSUMER
    BZQ B2B2C ADDRESS CONSUMER
    
        UTF-8
        UTF-8
        1.8
        
	 
        
          
    
		
		
			com.bzqb2b2c.address
			BZQ-B2B2C-ADDRESS-API
			1.0-SNAPSHOT
		
		
			com.bzqb2b2c.address
			BZQ-B2B2C-ADDRESS-PROVIDER
			1.0-SNAPSHOT
		
		
			com.bzqb2b2c.common
			BZQ-B2B2C-COMMON
			1.0-SNAPSHOT
				
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.2
        
        
            mysql
            mysql-connector-java
            runtime
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
	    
	        org.springframework.boot
	        spring-boot-devtools
	        true
	    
        
            org.apache.commons
            commons-lang3
            3.4
        
		
			com.google.code.gson
			gson
			2.8.5
		
		
            com.fasterxml.jackson.core
            jackson-core
        
        
            com.fasterxml.jackson.core
            jackson-databind
        
        
            com.fasterxml.jackson.datatype
            jackson-datatype-joda
        
        
            com.fasterxml.jackson.module
            jackson-module-parameter-names
        
        
        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.2.5
        
        
        
            com.alibaba
            druid-spring-boot-starter
            1.1.9
        
        
	 	 
			log4j
			log4j
			1.2.17
		
		 
		    org.springframework.boot
		    spring-boot-starter-logging
		
         
        
        
            com.alibaba.spring.boot
            dubbo-spring-boot-starter
            1.0.2
        
        
            org.apache.zookeeper
            zookeeper
            3.4.12
            
                
                    org.slf4j
                    slf4j-log4j12
                
            
        
        
            com.101tec
            zkclient
            0.10
        
        
            com.alibaba
            dubbo
            2.6.2
            
                
                    org.springframework
                    spring
                
            
        
        
            org.apache.curator
            curator-recipes
            4.0.0
        
        		
		
    
    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

 

BZQ-B2B2C-ADDRESS-PROVIDER:



	4.0.0
	com.bzqb2b2c.address
	BZQ-B2B2C-ADDRESS-PROVIDER
	1.0-SNAPSHOT
	jar
    BZQ-B2B2C-ADDRESS-PROVIDER
    BZQ B2B2C ADDRESS PROVIDER	
	     
    
        UTF-8
        UTF-8
        1.8
    
    
		
		
			com.bzqb2b2c.address
			BZQ-B2B2C-ADDRESS-API
			1.0-SNAPSHOT
		

		
			com.bzqb2b2c.common
			BZQ-B2B2C-COMMON
			1.0-SNAPSHOT
		
		        
		
			org.springframework.boot
			spring-boot-starter-web
			2.0.6.RELEASE
				
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.2
        		
 	 
        
            com.alibaba.spring.boot
            dubbo-spring-boot-starter
            1.0.2
        
        
            org.apache.zookeeper
            zookeeper
            3.4.12
            
                
                    org.slf4j
                    slf4j-log4j12
                
            
        
        
            com.101tec
            zkclient
            0.10
        
        
            com.alibaba
            dubbo
            2.6.2
            
                
                    org.springframework
                    spring
                
            
        
        
            org.apache.curator
            curator-recipes
            4.0.0
        		
 	         
        

 

BZQ-B2B2C-COMMON:



	4.0.0
	com.bzqb2b2c.common
	BZQ-B2B2C-COMMON
	1.0-SNAPSHOT
	jar
	
		UTF-8
		UTF-8
		1.8		
	

BZQ-B2B2C-ADDRESS-API:


4.0.0


UTF-8
UTF-8
1.8


MaVEN配置说明

依赖SPRING2工程:

org.springframework.boot spring-boot-starter-parent 2.0.6.RELEASE #### MAVEN引用其它工程:
   
		
		
			com.bzqb2b2c.address
			BZQ-B2B2C-ADDRESS-API
			1.0-SNAPSHOT
		
		
			com.bzqb2b2c.address
			BZQ-B2B2C-ADDRESS-PROVIDER
			1.0-SNAPSHOT
		
		
			com.bzqb2b2c.common
			BZQ-B2B2C-COMMON
			1.0-SNAPSHOT
		
   

SPRINGBOOT2配置说明

*配置方式
采用yml配置文件
BZQ-B2B2C-ADDRESS-CONSUMER
src
main
resources
application.yml

**application.yml
这个文件很简单,它只是引用各独立配置文件,个人喜欢这样管理

## include
spring:
    profiles:
        include: dubbo,mvc,mybatis,jdbc,log4j

MyBatis的相关配置
这个yml文件,一定要注意它的格式,每个:号都有个空格(TMD)

## MyBatis的相关配置
mybatis:
  # 映射文件位置 
  mapper-locations: classpath:com/soukong/center/address/mapper/*.xml
  # 别名扫描包
  type-aliases-package: com.soukong.center.address.entity
  # 输出SQL执行语句
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    map-underscore-to-camel-case: true   ###开启驼峰命名

## pagehelper分页相关配置
pagehelper:
    helperDialect: mysql
    reasonable: true
    supportMethodsArguments: true
    params: count=countSql
    returnPageInfo: check

MVC,说明商品,部署目录名

## 服务器端口号
spring:
  mvc:
    view:
      prefix: /
      suffix: .html
  resources:
    static-locations: /resources/,/static/
server:
  port: 89
  servlet: 
    context-path: /address

关于数据库参数的相关配置

## 关于数据库参数的相关配置
spring:
    datasource:
        name: mysql_test
        type: com.alibaba.druid.pool.DruidDataSource
        #druid相关配置
        druid:
          #监控统计拦截的filters
          filters: stat
          driver-class-name: com.mysql.jdbc.Driver
          #基本属性
          url: jdbc:mysql://localhost:3306/ware-center?characterEncoding=utf-8
          username: root
          password: 123456
          #配置初始化大小/最小/最大
          initial-size: 1
          min-idle: 1
          max-active: 20
          #获取连接等待超时时间
          max-wait: 600000
          #间隔多久进行一次检测,检测需要关闭的空闲连接
          time-between-eviction-runs-millis: 60000
          #一个连接在池中最小生存的时间
          min-evictable-idle-time-millis: 300000
          validation-query: SELECT 'x'
          test-while-idle: true
          test-on-borrow: false
          test-on-return: false
          #打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
          pool-prepared-statements: false
          max-pool-prepared-statement-per-connection-size: 20
  • Dubbo 服务提供者配置.
## Dubbo 服务提供者配置
spring:
  dubbo:
    appname: sample-base-service-provider
    registry: zookeeper://localhost:2181
    protocol: dubbo
    port: 20880     
  • log4j
## log4j
logging:
  level: 
    com.soukong.center: debug,info

ZooKeeper server

基本不要什么配置,注意环境中的端口要统一!
官网链接: 自己去下载.
图片: ![Alt](https://avSPRINGBOOT2.X入门学习_第1张图片

SPRINGBOOT2项目启动

SPRING启动有很多方式,我这里用Application.main()方式

// 启动类,它一定要放在最高的目录位置,我所有的东西放在com.soukong.center.address的子目录下,它就放com.soukong.center.address,如果位置不对,会完死你。

package com.soukong.center.address;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
/**
  * @作者:鲍忠启
 * @描述:SpringBoot主类-启动类 com.soukong.center.manage.dao
 */
@EnableDubbo   //启动DUBBO
@SpringBootApplication
@ImportResource({"classpath:appCtx-provider.xml"})  //这个是配置Dubbo用的。
@MapperScan({"com.soukong.center.address.dao" })  // 扫描你的DAO类
//@MapperScan("com.chengcheng.goods.dao.sys")
public class StartAddressApplication {

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

SPRINGBOOT2简单版本的启动类

package com.soukong.center.address;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
/**
 * @作者:BZQ
 * @描述:SpringBoot主类-启动类 com.soukong.center.manage.dao
 */
@SpringBootApplication
@MapperScan({"com.soukong.center.address.dao" })
public class StartAddressApplication {

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

Spring Boot 推荐目录结构

(1)代码层的结构
  根目录:com.springboot
    1.工程启动类(ApplicationServer.java)置于com.springboot.build包下
    2.实体类(domain)置于com.springboot.domain
    3.数据访问层(Dao)置于com.springboot.repository
    4.数据服务层(Service)置于com,springboot.service,数据服务的实现接口(serviceImpl)至于com.springboot.service.impl
    5.前端控制器(Controller)置于com.springboot.controller
    6.工具类(utils)置于com.springboot.utils
    7.常量接口类(constant)置于com.springboot.constant
    8.配置信息类(config)置于com.springboot.config
    9.数据传输类(vo)置于com.springboot.vo

(2)资源文件的结构
  根目录:src/main/resources
    1.配置文件(.properties/.json等)置于config文件夹下
    2.国际化(i18n))置于i18n文件夹下
    3.spring.xml置于META-INF/spring文件夹下
    4.页面以及js/css/image等置于static文件夹下的各自文件下

src/main/java:
              主程序入口 Application,可以通过直接运行该类来 启动 Spring Boot应用
src/main/resources:
              配置目录,该目录用来存放应用的一些配置信息,比如应用名、服务端口、数据库配置等。由于我们应用了Web模块,因此产生了 static目录与templates
              目录,前者用于存放静态资源,如图片、CSS、JavaScript等;后者用于存放Web页面的模板文件。
src/test:
              单元测试目录,生成的 ApplicationTests 通过 JUnit4实现,可以直接用运行 Spring Boot应用的测试。
application.properties/application.yml 
              用于存放程序的各种依赖模块的配置信息,比如 服务端口,数据库连接配置等。。。

控制层代码(controller)

BZQ-B2B2C-ADDRESS-CONSUMER工程。

package com.soukong.center.address.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;
import com.soukong.center.common.utils.PageUtils;
import com.soukong.center.address.dubbo.service.AreaDubboService;
import com.soukong.center.address.entity.AreaEntity;
import com.soukong.center.address.service.AreaService;
import com.soukong.center.common.utils.R;
import com.soukong.center.common.utils.RRException;

/**
 * 地区码表
 * 
 * @author 鲍忠启
 * @date 2019-02-27 15:50:24
 */
@Controller
@RequestMapping("/area")
public class AreaController {
	@Autowired   // 这个标签下面一定要有内容,不然坑死你
	private AreaDubboService areaService;
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	public R list(Integer page, Integer limit){
		Map map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);		
		//查询列表数据
		List areaList = areaService.queryList(map);
		int total = areaService.queryTotal(map);		
		PageUtils pageUtil = new PageUtils(areaList, total, limit, page);		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 */
	@ResponseBody
	@RequestMapping("/info/{areaid}")
	public R info(@PathVariable("areaid") Long areaid){
		AreaEntity area = (AreaEntity)areaService.queryObject(areaid);		
		return R.ok().put("area", area);
	}
	
	/**
	 */
	@ResponseBody
	@RequestMapping("/save")
	public R save(@RequestBody AreaEntity area){
		areaService.save(area);		
		return R.ok();
	}
	
	/**	
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update(@RequestBody AreaEntity area){
		areaService.update(area);	
		return R.ok();
	} 
	
}

服务层代码(DUBBO)

BZQ-B2B2C-ADDRESS-PROVIDER,这里我贴出DUBBO方式代码
`package com.soukong.center.address.dubbo.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.soukong.center.address.dubbo.service.AreaDubboService;
import com.soukong.center.address.entity.AreaEntity;
import com.soukong.center.address.service.AreaService;

/**

  • 地区Dubbo
  • @作者:鲍忠启

*/

@Service(“areaDubboService”)
public class AreaDubboServiceImpl implements AreaDubboService{

@Autowired
private AreaService areaService; 

/**  查询用户地址 */
public AreaEntity queryObject(Long addressId) {
	return areaService.queryObject(addressId);
}

/**  分页查询地址 */
public List queryList(Map map){
	return areaService.queryList(map);
}

/**  分页查询地址 */
public int queryTotal(Map map) {
	return areaService.queryTotal(map);
}

/**  新增  */
public Long save(AreaEntity userAddressInfo) {
	areaService.save(userAddressInfo);
	return 1L;
}
/**  修改  */
public void update(AreaEntity userAddressInfo) {
	areaService.update(userAddressInfo);
}
/**  新增+修改(合并使用)  */
public Long edit(AreaEntity userAddressInfo) {
	 
	return 1L;
}
/** 按地址ID删除地址 */
public void delete(Long addressId) {
	areaService.delete(addressId);
}

}
`

DUBBO接口定义

BZQ-B2B2C-ADDRESS-API工程。[^2]

package com.soukong.center.address.dubbo.service;

import java.util.List;
import java.util.Map;
import com.soukong.center.address.entity.AreaEntity;
//接口
public interface AreaDubboService {
	
	/**  查询用户地址 */
	public AreaEntity queryObject(Long addressId);
		/**  分页查询地址 */
	public List queryList(Map map);
		/**  分页查询地址 */
	public int queryTotal(Map map);
		/**  新增  */
	public Long save(AreaEntity userAddressInfo);
	/**  修改  */
	public void update(AreaEntity userAddressInfo);
	/**  新增+修改(合并使用)  */
	public Long edit(AreaEntity userAddressInfo);
	/** 按地址ID删除地址 */
	public void delete(Long addressId);
	
	
}

通用服务层代码

- 接口

package com.soukong.center.address.service;

import com.soukong.center.address.entity.AreaEntity;

import java.util.List;
import java.util.Map;

/**
 * 地区码表
 * @作者:鲍忠启
 * @date 2018-11-07 15:50:24
 */
public interface AreaService {
	
	AreaEntity queryObject(Long areaid);
	
	List queryList(Map map);
	
	int queryTotal(Map map);
	
	void save(AreaEntity area);
	
	void update(AreaEntity area);
	
	void delete(Long areaid);
	
	void deleteBatch(Long[] areaids);
	
	void deleteByLogicId(Long areaid);
	
	void deleteByLogicList(Long[] areaids);
	
	public List getPccList(Map map) ;
	
}

- 实现类

package com.soukong.center.address.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.soukong.center.address.dao.AreaDao;
import com.soukong.center.address.entity.AreaEntity;
import com.soukong.center.address.service.AreaService;


/**
 * 地区码表
 * @author 鲍忠启
 * @date 2018-11-07 15:50:24
 */
@Service("areaService")
public class AreaServiceImpl implements AreaService {
	@Autowired
	private AreaDao areaDao;
	
	public AreaEntity queryObject(Long areaid){
		return areaDao.queryObject(areaid);
	}
	
	public List queryList(Map map){
		return areaDao.queryList(map);
	}
	
	public int queryTotal(Map map){
		return areaDao.queryTotal(map);
	}
	
	public void save(AreaEntity area){
		areaDao.save(area);
	}
	
	public void update(AreaEntity area){
		areaDao.update(area);
	}
	
	public void delete(Long areaid){
		areaDao.delete(areaid);
	}
	
	public void deleteBatch(Long[] areaids){
		areaDao.deleteBatch(areaids);
	}
	
	public void deleteByLogicId(Long areaid){
		areaDao.deleteByLogicId(areaid);
	}
	
	public void deleteByLogicList(Long[] areaids){
		areaDao.deleteByLogicList(areaids);
	}
	public List getPccList(Map map) {
		return areaDao.getPccList(map);
	}
}

SPRINGBOOT2持久层

- 接口

package com.soukong.center.address.dao;

import com.soukong.center.address.entity.AreaEntity;
import java.util.Map;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;

/**
 * 地区码表
 * @作者:鲍忠启 
 * @date 2018-11-07 15:50:24
 */
public interface AreaDao extends BaseDao {	
	public List getPccList(Map map) ;
}

- MAPPER文件






	

	
	
 	
	 
	
		insert into tb_area
		
			
				areaCode,
			
			
				areaName,
			
			
				level,
			
			
				cityCode,
			
			
				center,
			
			
				parentCode,
			
			
				create_time,
			
			
				update_time,
			
			
				del_flag,
			
			
				op_id,
			
			
				version,
			
		
		
			
				#{areacode},
			
			
				#{areaname},
			
			
				#{level},
			
			
				#{citycode},
			
			
				#{center},
			
			
				#{parentcode},
			
			
				#{createTime},
			
			
				#{updateTime},
			
			
				#{delFlag},
			
			
				#{opId},
			
			
				#{version},
			
		
	
	 
	
		update tb_area 
		
			`areaCode` = #{areacode}, 
			`areaName` = #{areaname}, 
			`level` = #{level}, 
			`cityCode` = #{citycode}, 
			`center` = #{center}, 
			`parentCode` = #{parentcode}, 
			`create_time` = #{createTime}, 
			`update_time` = #{updateTime}, 
			`del_flag` = #{delFlag}, 
			`op_id` = #{opId}, 
			`version` = #{version}
		
		where areaId = #{areaid}
	
	
	
		delete from tb_area where areaId = #{value}
	
	
	
		delete from tb_area where areaId in 
		
			#{areaid}
		
	
	
	
		update tb_area set del_flag=1	 where 1=1 and areaId = #{value}
	
	
	
		update tb_area	set del_flag=1	 where 1=1 and areaId in
		
			#{areaid}
		
	

	


SPRINGBOOT2持久层有很多实现方式,我这里用mybatis.

MYBATIS说明

pom.xml文件中需要加入

  • 依赖
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.2
        
        
            mysql
            mysql-connector-java
            runtime
        
        
        
            com.alibaba
            druid-spring-boot-starter
            1.1.9
        ```

- application-mybatis.yml

##springboot2 MyBatis的相关配置
mybatis:
  # 映射文件位置 
  mapper-locations: classpath:com/soukong/center/address/mapper/*.xml   ### SQL文件目录,可以用通配符方式
  # 别名扫描包
  type-aliases-package: com.soukong.center.address.entity    ### 实体类目录 
  # 输出SQL执行语句
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    map-underscore-to-camel-case: true   ###开启驼峰命名
## pagehelper分页相关配置
pagehelper:
    helperDialect: mysql
    reasonable: true
    supportMethodsArguments: true
    params: count=countSql
    returnPageInfo: check

SPRINGBOOT2配置DUBBO

- 启动,要启动消费者、生产者哦

package com.soukong.center.manage;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
import com.alibaba.dubbo.config.spring.context.annotation.DubboComponentScan;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;

/**  消费者
 * @作者:鲍忠启
 * @描述:SpringBoot主类-启动类 com.soukong.center.manage.dao
 */
@EnableDubbo
//@EnableDubboConfiguration
@SpringBootApplication
@ImportResource({"classpath:appCtx-consumer.xml"})
//@DubboComponentScan(basePackages = "com.soukong.center.address.dubbo.service")
@MapperScan({"com.soukong.center.manage.mapper","com.soukong.center.manage.mapper.sys","com.soukong.center.manage.dao"})
//@MapperScan("com.chengcheng.goods.dao.sys")
public class StartManageApplication {

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

//package com.soukong.center.address;

package com.soukong.center.address;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;

import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;


/**  生产者
 * @作者:鲍忠启
 * @描述:SpringBoot主类-启动类 com.soukong.center.manage.dao
 */
@EnableDubbo
@SpringBootApplication
@ImportResource({"classpath:appCtx-provider.xml"})
@MapperScan({"com.soukong.center.address.dao" })
//@MapperScan("com.chengcheng.goods.dao.sys")
public class StartAddressApplication {

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

- 配置 pom.xml 文件中需要有:

       
        
            com.alibaba.spring.boot
            dubbo-spring-boot-starter
            1.0.2
        
        
            org.apache.zookeeper
            zookeeper
            3.4.12
            
                
                    org.slf4j
                    slf4j-log4j12
                
            
        
        
            com.101tec
            zkclient
            0.10
        
        
            com.alibaba
            dubbo
            2.6.2
            
                
                    org.springframework
                    spring
                
            
        
        
            org.apache.curator
            curator-recipes
            4.0.0
        
        	
  • DUBBO配置,我采用XML方式,和以前的一样,有两部分哦,我都放在/resouces/appCtx-provider.xml

注册方





    


调用方





	

    
    
    
    

注意有个是以
一个是以:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'buyerOrderController': Unsatisfied dependency expressed through field 'orderService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderServiceImpl': Unsatisfied dependency expressed through field 'productService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productServiceImpl': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productInfoRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.imooc.dataobject.ProductInfo com.imooc.repository.ProductInfoRepository.findOne(java.lang.String)! No property findOne found for type ProductInfo!
Description:

Field sysMenuDao in com.soukong.center.manage.service.impl.SysMenuServiceImpl required a bean of type 'com.soukong.center.manage.dao.SysMenuDao' 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 'com.soukong.center.manage.dao.SysMenuDao' in your configuration.
java.lang.IllegalStateException: 
Error 
processing 
condition on com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.dataSource
 java.lang.IllegalStateException: 
Error processing condition on com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.dataSource
java.lang.IllegalStateException: Error processing condition on com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.dataSource
 Caused by: java.lang.NoClassDefFoundError: com/alibaba/druid/filter/logging/Log4j2Filter
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Generic.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver
[ERROR] Failed to execute goal on project BZQ-B2B2C-MANEGE-CONTROLLER: Could not resolve dependencies for project com.bzqb2b2c.manage:BZQ-B2B2C-MANEGE-CONTROLLER:war:1.0-SNAPSHOT: The following artifacts could not be resolved: com.bzqb2b2c.manage:BZQ-B2B2C-MANEGE-API:jar:1.0-SNAPSHOT, com.bzqb2b2c.manage:BZQ-B2B2C-MANEGE-SERVICE:jar:1.0-SNAPSHOT: Could not find artifact com.bzqb2b2c.manage:BZQ-B2B2C-MANEGE-API:jar:1.0-SNAPSHOT -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
log4j:WARN No appenders could be found for logger (org.springframework.boot.devtools.settings.DevToolsSettings).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/other/maven/maven-dependcies/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/other/maven/maven-dependcies/org/slf4j/slf4j-log4j12/1.7.19/slf4j-log4j12-1.7.19.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 [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Consider defining a bean of type 'com.chengcheng.goods.service.sys.SysUserService' in your configuration.
java.lang.IllegalStateException: Configuration error:  No realms have been configured!  One or more realms must be present to execute an authentication attempt.

java.lang.IllegalStateException: Configuration error:  No realms have been configured!  One or more realms must be present to execute an authentication attempt.
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.b2b2c.ware.center.dao.ware.ConfigInfoDao.queryList
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).

小结

一句话,坑无数,嘻嘻

源代码下载
版本3

版本2

版本1

你可能感兴趣的:(java,SPRINGBOOT)