当前位置: 首页 > 知识库问答 >
问题:

Spring Boot MVC“考虑定义bean”

龙霖
2023-03-14

我的Spring Boot MVC REST应用程序有问题。我试图自己解决这个问题几天,但还没有找到解决方案。希望你能帮我:)

我的主应用程序:

package com.abc.mapserver;

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

我的配置类:

package com.abc.mapserver;

@Configuration
@EnableWebMvc
public class MapServerConfiguration implements WebMvcConfigurer {
    @Value("${mapserver.connection-string}")
    private String connectionString;
}

TestTableRepository.java:

package com.abc.mapserver.infrastructure.repository;

@Repository
public interface TestTableRepository extends JpaRepository<TestTable, Long> {}

IVectorData:

package com.abc.mapserver.infrastructure.service;

public interface IVectorData {
    // Interface Methods...
}

这里是:

package com.abc.mapserver.infrastructure.endpoints;

public class IVectorDataEndpoint {

IVectorData iVectorData;
TestTableRepository testTableRepository;

    **@Autowired
    public void setTestTableRepository(TestTableRepository testTableRepository) {
        this.testTableRepository = testTableRepository;
    }**

    @Autowired
    public void setiVectorData(IVectorData iVectorData) {
        this.iVectorData = iVectorData;
    }
}

问题是Spring找不到“testTableRepository”Bean。

错误代码:

Description:

Parameter 0 of method setTestTableRepository in com.abc.mapserver.infrastructure.endpoints.IVectorDataEndpoint required a bean of type 'com.abc.mapserver.infrastructure.repository.TestTableRepository' that could not be found.

Action:

Consider defining a bean of type 'com.abc.mapserver.infrastructure.repository.TestTableRepository' in your configuration.

但有一件有趣的事是,第二个自动连线的候选者“IVectorData”工作正常,已经与邮递员一起测试过,可以解决所有问题。

对于其他bean,相同的过程、相同的文件结构都不起作用。

格拉德尔:

dependencies {
    implementation "org.springframework.boot:spring-boot-starter-jdbc:${spring_boot_version}"
    implementation "org.springframework.boot:spring-boot-starter-web:${spring_boot_version}"
    implementation "org.springframework.boot:spring-boot-starter-thymeleaf:${spring_boot_version}"
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.hibernate:hibernate-spatial'
    implementation 'org.apache.commons:commons-lang3:3.0'
    implementation 'org.springdoc:springdoc-openapi-ui:1.3.7'
    implementation 'org.apache.commons:commons-lang3:3.10'
    implementation 'com.google.guava:guava:29.0-jre'
    implementation 'org.locationtech.jts:jts-core:1.18.1'
    runtimeOnly 'org.postgresql:postgresql:42.2.13'

    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

共有1个答案

曾嘉福
2023-03-14

能否尝试将@组件添加到IVectorDataEndpoint类中?另外,您确定在初始化TestTableRepository时没有错误吗?

 类似资料:
  • 我有一个Spring Boot项目,其中Flyway与JPA一起使用。 该项目运行完全正常。由于一些要求,我不得不改变Flyway加载的顺序,以便在Hibernate后加载。我搜索并找到了以下解决方案 。我按照上述链接中的答案创建了。现在,当我运行该应用程序时,它会给我以下错误, 现在我对Spring Boot相当陌生,因此无法理解此错误,并且在网上找不到与此错误相关的任何内容。

  • 我对整个Spring的生态系统都是陌生的。我一直在学习一些教程,能够创建一个Spring Boot应用程序并执行crud操作。然后我开始把这个项目改成mybatis的标准。 我已经尝试了许多其他类似问题的答案,但到目前为止没有一个是有效的。 下面是问题陈述: 实现类实现为: 我的Mapper类如下所示: 我的Mapper.xml课是: 最后是我的控制器类: 我得到的错误是: 描述: com.cru

  • 我试图在Spring Boot中创建一个简单的REST服务。在我使用CrudRepository之前,一切都很好。现在我得到了这个错误- ***应用程序启动失败 描述: 公司中的现场er。Spring靴。io。受雇者EmployeeService需要“company”类型的bean。Spring靴。io。受雇者找不到EmployeeRepo“”。 措施: 考虑定义一个“company”类型的bea

  • 我正在做SpringBoot项目,并遵循一些测试SpringBoot的说明。 当我尝试将mysql DB与项目连接时,服务找不到映射器。 我不知道为什么它找不到映射器... 这是服务代码和 这是映射程序代码 下面的错误是 我将发布我的包裹设置的图片。。。

  • 客户服务实施 客户服务界面 客户映射器 主类 错误- 应用程序启动失败 说明: com中的字段映射器。应用服务实施。CustomerServiceImpl需要“com”类型的bean。应用映射器。找不到CustomerMapper“”。 措施: 考虑定义“com”类型的bean。应用映射器。配置中的CustomerMapper。