我的 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> {}
向量資料:
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”可以正常作業,已經與 Postman 一起測驗,可以正常作業。
相同的程序,相同的檔案結構,與其他 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'
}
}
uj5u.com熱心網友回復:
您可以嘗試顯式啟用 JPA 存盤庫嗎?像下面
@SpringBootApplication
@EnableJpaRepositories(basePackages = { com.abc.mapserver.infrastructure.repository })
公共類 MapServerApplication {
公共靜態無效主要(字串[]引數){
SpringApplication.run(MapServerApplication.class, args);
}
}
此外,在啟動檢查日志時,它應該顯示類似
"Finished Spring data repository scanning in 100 ms etc etc " Found 1 repository....
uj5u.com熱心網友回復:
您可以嘗試添加@Component到IVectorDataEndpoint班級嗎?TestTableRepository另外你確定初始化時沒有錯誤嗎?
uj5u.com熱心網友回復:
我可以保存第一個問題。這是我的資料源未配置。
但是現在我的 JPARepository 的 .save() 方法按預期將我的物體寫入另一個表。
@Override
public TestTable testJPA(TestTable testTable) {
return testTableRepository.save(testTable);
}
實際上,它應該將其寫入表“testTable”,但它會創建一個名為“test_table”的新表并將值寫入其中,但至少是正確的。
為什么它自己在里面寫下劃線?^^
有任何想法嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/493424.html
上一篇:為什么我不能使用來自gocloak中Login()的訪問令牌在KeyCloak中創建新客戶端?
下一篇:該用戶帳戶所有者的權限
