最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Strange error about entity class: Error creating bean with name 'xxxController' defined in file [] - Stac

programmeradmin0浏览0评论

When I try to test the database briefly using the following code (additions: My database has only one id field in the corresponding table), it reports an error.

@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(description = "Node")
@TableName(keepGlobalPrefix = true, value = "node")
public class Node {
    @TableId(type = IdType.NONE)
    private Integer id;
}

error info:

Error creating bean with name 'xxxController' defined in file []. Unsatisfied dependency expressed through constructor parameter 0; nested exception is .springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'xxxServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is .springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'xxxMapper' defined in file []: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is .springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is .springframework.beans.BeanInstantiationException: Failed to instantiate [.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is .springframework.core.NestedIOException: Failed to parse mapping resource: 'file [xxx]'; nested exception is java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 0

But all I have to do is add a name field (even though it doesn't exist in the corresponding table) and the code works fine.

@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(description = "Node")
@TableName(keepGlobalPrefix = true, value = "node")
public class Node {
    @TableId(type = IdType.NONE)
    private Integer id;

    private String name;
}

Although this problem doesn't affect my program in any way, I'd still like to know why it's happening.

Just in case, I'll post the general information about Contrller, Service, and Mapper (none of them are actually used much).

Controller:

@Api(tags = "dataCatalog")
@RequestMapping("/api/dataCatalog")
@RestController
@AllArgsConstructor
public class DataCatalogController {
    private final NodeService nodeService;
    
    @GetMapping("/getDataCatalog")
    @ApiOperation("getDataCatalog")
    public Result<List<Node>> getDataCatalogNode() {
        return Result.success(nodeService.list());
    }
}

Service:

public interface NodeService extends IService<Node> {

}

ServiceImpl:

@Service
@RequiredArgsConstructor
public class NodeServiceImpl extends ServiceImpl<NodeMapper, Node> implements NodeService {
}

Mapper:

@Mapper
public interface NodeMapper extends BaseMapper<Node> {

}

Mapper.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis//DTD Mapper 3.0//EN" ".dtd">
<mapper namespace="cn.workflow.business.modules.catalog.mapper.NodeMapper">
</mapper>

Finally, thanks a lot for answering

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论