這似乎是一個簡單的問題,但我無法讓它作業我有一個簡單的 spring boot java 專案。java.srcDirs設定為src。我假設類路徑src現在也有。
我可以將代碼檔案直接放入src目錄嗎?還是我必須創建一個子目錄?
發生的事情是,如果我創建一個子目錄demo,那么我可以package demo;在演示中的代碼檔案中進行設定。但我不能為src目錄中的檔案設定任何包名。如果我將其留空或“”,我會收到錯誤訊息
declared package "src" does not match the expected package ""
如果我完全省略了包名,那么 spring boot 就會出錯
** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.
2022-10-01 13:17:51.010 WARN 7999 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/home/user/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.7.4/1848e5e8e474cc880a7708f03f750736665d4157/spring-boot-autoconfigure-2.7.4.jar!/org/springframework/boot/autoconfigure/r2dbc/ConnectionFactoryConfigurations$PoolConfiguration.class]; nested exception is java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryConfigurations$PoolConfiguration due to io/r2dbc/spi/ValidationDepth not found. Make sure your own configuration does not rely on that class. This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)
2022-10-01 13:17:51.021 INFO 7999 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-10-01 13:17:51.036 ERROR 7999 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/home/user/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.7.4/1848e5e8e474cc880a7708f03f750736665d4157/spring-boot-autoconfigure-2.7.4.jar!/org/springframework/boot/autoconfigure/r2dbc/ConnectionFactoryConfigurations$PoolConfiguration.class]; nested exception is java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryConfigurations$PoolConfiguration due to io/r2dbc/spi/ValidationDepth not found. Make sure your own configuration does not rely on that class. This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)
包應該在 srcdir/classpath 的子目錄中是 java 標準的一部分嗎?這里很困惑。
uj5u.com熱心網友回復:
您可以將以下類放在源根目錄中。
package demo;
public class MyClass {
}
當你編譯代碼時,類 MyClass 將被放入目錄 demo 中的輸出目錄中。
由于此方法有效,因此不推薦。包結構和目錄結構應該匹配。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/511772.html
