elunez / eladmin

eladmin jpa 版本:项目基于 Spring Boot 2.6.4、 Jpa、 Spring Security、Redis、Vue的前后端分离的后台管理系统,项目采用分模块开发方式, 权限控制采用 RBAC,支持数据字典与数据权限管理,支持一键生成前后端代码,支持动态路由
https://eladmin.vip/demo
Apache License 2.0
21.19k stars 7.34k forks source link

新建模块 不同包名 请求 404移动后 依赖注入失败 #480

Closed TomYule closed 4 years ago

TomYule commented 4 years ago

新建模块 不同包名 依赖注入失败 版本: v2.5 环境:本地 复现步骤: 新建maven eladmin-bengbu模块

<?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">
    <parent>
        <artifactId>eladmin</artifactId>
        <groupId>me.zhengjie</groupId>
        <version>2.5</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>eladmin-bengbu</artifactId>

    <dependencies>
        <dependency>
            <groupId>me.zhengjie</groupId>
            <artifactId>eladmin-common</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>me.zhengjie</groupId>
            <artifactId>eladmin-tools</artifactId>
            <version>2.5</version>
        </dependency>

    </dependencies>
</project>

创建 生成模块 包名为com.xxxx 请求一直提示404 后把OrderRecordController模块移动至system模块下 system引入maven

        <dependency>
            <groupId>me.zhengjie</groupId>
            <artifactId>eladmin-bengbu</artifactId>
            <version>2.5</version>
        </dependency>

OrderRecordController代码


import me.zhengjie.annotation.Log;
import com.xxxx.domain.OrderRecord;
import com.xxxx.service.OrderRecordService;
import com.xxxx.service.dto.OrderRecordQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://el-admin.vip
* @author haiming
* @date 2020-09-08
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "订单记录管理")
@RequestMapping("/api/bengbu/OrderRecord")
public class OrderRecordController {

    private final OrderRecordService OrderRecordService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('OrderRecord:list')")
    public void download(HttpServletResponse response, OrderRecordQueryCriteria criteria) throws IOException {
        OrderRecordService.download(OrderRecordService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询订单记录")
    @ApiOperation("查询订单记录")
    @PreAuthorize("@el.check('OrderRecord:list')")
    public ResponseEntity<Object> query(OrderRecordQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(OrderRecordService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增订单记录")
    @ApiOperation("新增订单记录")
    @PreAuthorize("@el.check('OrderRecord:add')")
    public ResponseEntity<Object> create(@Validated @RequestBody OrderRecord resources){
        return new ResponseEntity<>(OrderRecordService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改订单记录")
    @ApiOperation("修改订单记录")
    @PreAuthorize("@el.check('OrderRecord:edit')")
    public ResponseEntity<Object> update(@Validated @RequestBody OrderRecord resources){
        OrderRecordService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除订单记录")
    @ApiOperation("删除订单记录")
    @PreAuthorize("@el.check('OrderRecord:del')")
    @DeleteMapping
    public ResponseEntity<Object> delete(@RequestBody String[] ids) {
        OrderRecordService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}

日志提供:

elAdmin- 2020-09-08 14:37:44 [main] INFO  org.quartz.core.QuartzScheduler - Scheduler meta-data: Quartz Scheduler (v2.3.0) 'QuartzScheduler' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

elAdmin- 2020-09-08 14:37:44 [main] INFO  org.quartz.impl.StdSchedulerFactory - Quartz scheduler 'QuartzScheduler' initialized from an externally provided properties instance.
elAdmin- 2020-09-08 14:37:44 [main] INFO  org.quartz.impl.StdSchedulerFactory - Quartz scheduler version: 2.3.0
elAdmin- 2020-09-08 14:37:44 [main] INFO  org.quartz.core.QuartzScheduler - JobFactory set to: me.zhengjie.modules.quartz.config.QuartzConfig$QuartzJobFactory@517f9ba3
elAdmin- 2020-09-08 14:37:44 [main] INFO  org.quartz.core.QuartzScheduler - Scheduler QuartzScheduler_$_NON_CLUSTERED started.
elAdmin- 2020-09-08 14:37:45 [main] WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderRecordController' defined in file [/Users/krxxxx/IdeaProjects/eladmin/eladmin-system/target/classes/me/zhengjie/modules/system/rest/OrderRecordController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xxxx.service.OrderRecordService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
elAdmin- 2020-09-08 14:37:45 [main] INFO  org.quartz.core.QuartzScheduler - Scheduler QuartzScheduler_$_NON_CLUSTERED shutting down.
elAdmin- 2020-09-08 14:37:45 [main] INFO  org.quartz.core.QuartzScheduler - Scheduler QuartzScheduler_$_NON_CLUSTERED paused.
elAdmin- 2020-09-08 14:37:45 [main] INFO  org.quartz.core.QuartzScheduler - Scheduler QuartzScheduler_$_NON_CLUSTERED shutdown complete.
elAdmin- 2020-09-08 14:37:45 [main] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
elAdmin- 2020-09-08 14:37:45 [main] INFO  c.alibaba.druid.pool.DruidDataSource - {dataSource-1} closing ...
elAdmin- 2020-09-08 14:37:45 [main] INFO  c.alibaba.druid.pool.DruidDataSource - {dataSource-1} closed
elAdmin- 2020-09-08 14:37:45 [main] INFO  o.a.catalina.core.StandardService - Stopping service [Tomcat]
elAdmin- 2020-09-08 14:37:45 [main] INFO  o.s.b.a.l.ConditionEvaluationReportLoggingListener - 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
elAdmin- 2020-09-08 14:37:45 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - 

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

Description:

Parameter 0 of constructor in me.zhengjie.modules.system.rest.OrderRecordController required a bean of type 'com.xxxx.service.OrderRecordService' that could not be found.

Action:

Consider defining a bean of type 'com.xxxx.service.OrderRecordService' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:49154', transport: 'socket'

Process finished with exit code 1

请问 依赖注入是在哪配置的 为什么会找不到呢 编译 没有问题 启动失败

elunez commented 4 years ago

image

TomYule commented 4 years ago

建议 main 方法加入 @ComponentScan(basePackages = {"me.zhengjie.**"}) 方便 小白理解

huangxiaoyu commented 2 years ago

image 添加几个注解,吧自己的包名写进去就行了