org.springframework.beans.factory.BeanCreationException

标题SpringBoot启动报错:org.springframework.beans.factory.BeanCreationException

springboot初学,实在查不到问题,望大神们给解解惑!
报错信息是bean注入异常,不知道这个应该怎么去配置
报错信息:

2021-04-21 10:02:45.928  INFO 13492 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-04-21 10:02:45.928  INFO 13492 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1201 ms
2021-04-21 10:02:46.276  WARN 13492 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deleteController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ItemsDeleteService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemsDeteleMapper' defined in file [E:\zhg\ams\target\classes\com\xmx\ams\mapper\ItemsDeteleMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
2021-04-21 10:02:46.288  INFO 13492 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-04-21 10:02:46.305  INFO 13492 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-21 10:02:46.324 ERROR 13492 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deleteController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ItemsDeleteService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemsDeteleMapper' defined in file [E:\zhg\ams\target\classes\com\xmx\ams\mapper\ItemsDeteleMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

Controller层代码

package com.xmx.ams.controller;


import com.xmx.ams.service.ItemsDeleteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@Api(tags = "10.删除服务操作")
@Controller
@RequestMapping("/delete")
public class DeleteController {

   @Resource
    private ItemsDeleteService itemsDeleteService;
    /**
     * 删除类型
     * @param typeId 类型编号
     * @return map集合
     */
    @ApiOperation("删除类型")
    @ApiImplicitParams({@ApiImplicitParam(name = "name", value = "功能权限名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "Integer", paramType = "query")})
    @RequestMapping("/deleteType")
    @ResponseBody
    public Map deleteType(Long typeId){
        return itemsDeleteService.deleteType(typeId);
    }
    /**
     * 删除物品
     * @param itemsId 物品编号
     * @return map集合
     */
    @ApiOperation("删除物品")
    @ApiImplicitParams({@ApiImplicitParam(name = "name", value = "功能权限名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "Integer", paramType = "query")})
    @RequestMapping("/deleteItems")
    @ResponseBody
    public Map deleteItems(Long itemsId){
        return itemsDeleteService.deleteType(itemsId);
    }
    /**
     * 删除供应商
     * @param supplierId 供应商编号
     * @return map集合
     */
    @ApiOperation("删除供应商")
    @ApiImplicitParams({@ApiImplicitParam(name = "name", value = "功能权限名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "Integer", paramType = "query")})
    @RequestMapping("/deleteSupplier")
    @ResponseBody
    public Map deleteSupplier(Long supplierId){
        return itemsDeleteService.deleteType(supplierId);
    }
    /**
     * 删除门店信息
     * @param storeId 门店编号
     * @return map集合
     */
    @ApiOperation("删除门店信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "name", value = "功能权限名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "Integer", paramType = "query")})
    @RequestMapping("/deleteStore")
    @ResponseBody
    public Map deleteStore(Long storeId){
        return itemsDeleteService.deleteType(storeId);
    }
}

Service层

package com.xmx.ams.service;

import com.xmx.ams.mapper.ItemsDeteleMapper;
import com.xmx.ams.utils.Tips;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhg
 * date 2021/04/09
 * 删除实现
 */
@Service
public class ItemsDeleteService {
    @Resource
    private ItemsDeteleMapper itemsDeteleMapper;
    //提示集合,返回信息至前端
    Map<String,Object> tipsMap = new HashMap<>();

    /**
     * 类型删除
     * @param typeId 类型id
     * @return 返回带有提示的map集合
     */
    public Map deleteType(Long typeId){
        if (typeId==null && typeId.equals("")){
            tipsMap.put(Tips.DELETE_ERROR.toString(),"删除错误异常");
        }else{
            if (itemsDeteleMapper.deleteItemsType(typeId)>0){
                tipsMap.put(Tips.DELETE_SUCCESS.toString(),"删除成功");
            }
        }
        return  tipsMap;
    }

    /**
     * 物品删除
     * @param itemsId 物品编号
     * @return 返回带有提示的map集合
     */
    public Map deleteItems(Long itemsId){
        if (itemsId==null && itemsId.equals("")){
            tipsMap.put(Tips.DELETE_ERROR.toString(),"删除错误异常");
        }else{
            if (itemsDeteleMapper.deleteItemsType(itemsId)>0){
                tipsMap.put(Tips.DELETE_SUCCESS.toString(),"删除成功");
            }
        }
        return  tipsMap;
    }

    /**
     * 删除供应商信息
     * @param supplierId 供应商编号
     * @return 返回带有提示的map集合
     */
    public Map deleteSupplier(Long supplierId){
        if (supplierId==null && supplierId.equals("")){
            tipsMap.put(Tips.DELETE_ERROR.toString(),"删除错误异常");
        }else{
            if (itemsDeteleMapper.deleteItemsType(supplierId)>0){
                tipsMap.put(Tips.DELETE_SUCCESS.toString(),"删除成功");
            }
        }
        return  tipsMap;
    }

    /**
     * 删除门店信息
     * @param storeId 门店编号
     * @return 返回带有提示的map集合
     */
    public Map deleteStore(Long storeId){
        if (storeId==null && storeId.equals("")){
            tipsMap.put(Tips.DELETE_ERROR.toString(),"删除错误异常");
        }else{
            if (itemsDeteleMapper.deleteItemsType(storeId)>0){
                tipsMap.put(Tips.DELETE_SUCCESS.toString(),"删除成功");
            }
        }
        return  tipsMap;
    }
}

Mapper

package com.xmx.ams.mapper;

import org.apache.ibatis.annotations.Delete;
/**
 * @author zhg
 * date 2021/04/09
 * 删除接口类
 */
public interface ItemsDeteleMapper {
    /**
     * 删除类型信息
     * @param typeId 类型编号
     * @return 影响行数
     */
    @Delete("DELETE FROM `module_ums_ams_items_type` WHERE `type_id` = #{typeId}")
    public int deleteItemsType(Long typeId);

    /**
     * 删除物品信息
     * @param itemsId 物品Id
     * @return 影响行数
     */
    @Delete("DELETE FROM `module_ums_ams_items` WHERE `items_id` = #{itemsId}")
    public int deleteItems(Long itemsId);

    /**
     * 删除供应商信息
     * @param supplierId 供应商Id
     * @return 影响行数
     */
    @Delete("DELETE FROM `module_ums_ams_supplier` WHERE `supplier_id` = #{supplierId}")
    public int deleteSupplier(Long supplierId);

    /**
     * 删除门店信息
     * @param storeId 门店Id
     * @return 影响行数
     */
    @Delete("DELETE FROM `module_ums_ams_store` WHERE store_id = #{storeId}")
    public int deleteStore(Long storeId);
}

appliction.yml

spring:
  #配置数据库链接
  datasource:
    username: root
    password: 123456
    url: jdbc:mysql://localhost:3306/module-uums?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8
    driver-class-name: com.mysql.cj.jdbc.Driver


    #以下是druid增加的配置
    type: com.alibaba.druid.pool.DruidDataSource
    #配置初始化大小,最小,最大
    initialSize: 5
    minIdle: 5
    maxActive: 20
    #配置获取连接等待超时的时间
    maxWait: 60000
    #配置间隔多久进行一次检测,检测需要关闭的空链接,单位是毫秒
    timeBetweenEvictionRunsMillis: 60000
    #配置一个链接在池中的最小生存设的时间,单位为毫秒
    minEvictableTimeMillis: 300000
    validationQuery: SELECT 1 FROM DUAL
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    #打开PSCache,并且指定每个链接上PSCache的大小
    poolPreparedStatements: true
    maxPoolPreparedStatementPerConnectionSize: 20
    #配置监控统计拦截的filters 去掉后监控界面SQL无法统计,wall 用于防火墙
    filters:
      commons-log.connection-logger-name: stat,wall,log4j
    # 合并多个DruidDataSource的监控数据
    useGlobalDataSourceStat: true
    # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
    connectionProperties: druid.stat.merdeSql=true;druid.stat.slowSqlMillis=500

#关于mybatis的配置
mybatis:
  #配置mybatis的全局配置文件
  config-location: classpath:resources/Mybatis-config.xml
  #配置
  mapper-locations: classpath:mapper/*

#配置端口号为8081
server:
  port: 8081


启动类

package com.xmx.ams;

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


@SpringBootApplication
@MapperScan("com.xmx.ams.mapper")
public class AmsApplication {

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

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值