관리 메뉴

프로그래밍 삽질 중

[spring-boot]intllij 내 Bean을 찾지 못해서 발생하는 오류 본문

과거 프로그래밍 자료들/컴퓨터설정&오류

[spring-boot]intllij 내 Bean을 찾지 못해서 발생하는 오류

평부 2021. 7. 5. 15:20

※ 프로젝트 내 application(해당 프로젝트 내 이름은 InventoryAppApplication)  작동 시 아래 오류가 계속 나옴

※ 참고로 Process finished with exit code 0 해결책을 찾을 경우 dependencies에 org.springframework.boot:spring-boot-starter-web'를 확인하라는 답변이 나옴

→ 초기 설정(start.spring.io)에 처음부터 추가한 의존성이라 문제와 상관 없었음

※ 참고 사이트 

https://github.com/HomoEfficio/dev-tips/blob/master/Spring%20-%20Autowiring%20%EA%B4%80%EB%A0%A8%20%EC%98%A4%EB%A5%98.md

 

HomoEfficio/dev-tips

개발하다 마주쳤던 작은 문제들과 해결 방법 정리. Contribute to HomoEfficio/dev-tips development by creating an account on GitHub.

github.com

 

 

 

오류(문제점)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
C:\Programs\Java\jdk-11.0.7\bin\java.exe "-javaagent:D:\Programs\IntelliJ IDEA Community Edition 2021.1.2\lib\idea_rt.jar=59238:D:\Programs\IntelliJ IDEA Community Edition 2021.1.2\bin" -Dfile.encoding=UTF-8 -classpath D:\Programs\InventoryApp\InventoryApp\out\production\classes;D:\Programs\InventoryApp\InventoryApp\out\production\resources;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-data-jpa\2.5.2\5038e48790990bc137c9a7e1cd97901a1350eb37\spring-boot-starter-data-jpa-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-thymeleaf\2.5.2\bbf0322ed2d1e9b6b7e7e46903ceb1bba0dd3ba2\spring-boot-starter-thymeleaf-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-web\2.5.2\9d68318f6607728e253030aa145e529bae9b0883\spring-boot-starter-web-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\1.7.31\9545c9cb71de4c18d97a91e32ef0be6f3f6661b7\slf4j-api-1.7.31.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.12.3\deb23fe2a7f2b773e18ced2b50d4acc1df8fa366\jackson-core-2.12.3.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.data\spring-data-jpa\2.5.2\37a27171338da87485cdf66a40596195433d1db\spring-data-jpa-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-jdbc\2.5.2\de9142ad6a67d2ec7d58465ab8d2fcf759f24d25\spring-boot-starter-jdbc-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-aop\2.5.2\1877448bb875154c2558e385f4590c648ada5f11\spring-boot-starter-aop-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\jakarta.transaction\jakarta.transaction-api\1.3.3\c4179d48720a1e87202115fbed6089bdc4195405\jakarta.transaction-api-1.3.3.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\jakarta.persistence\jakarta.persistence-api\2.2.3\8f6ea5daedc614f07a3654a455660145286f024e\jakarta.persistence-api-2.2.3.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.hibernate\hibernate-core\5.4.32.Final\99a5e10bf455337014c190e141ec631e9ff71663\hibernate-core-5.4.32.Final.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework\spring-aspects\5.3.8\863f531cc3ea9d82d391d17c8eb33732e7a864b6\spring-aspects-5.3.8.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.thymeleaf\thymeleaf-spring5\3.0.12.RELEASE\aa640b214411978a23cbe271c3fb9569d1bda608\thymeleaf-spring5-3.0.12.RELEASE.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.thymeleaf.extras\thymeleaf-extras-java8time\3.0.4.RELEASE\36e7175ddce36c486fff4578b5af7bb32f54f5df\thymeleaf-extras-java8time-3.0.4.RELEASE.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter\2.5.2\5aa5345f60cd3fbca331c05015e0700553448d66\spring-boot-starter-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-json\2.5.2\6af2e2d4fcf02fcda700dbbcd4643e78d31bcc8c\spring-boot-starter-json-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-tomcat\2.5.2\ed7d2ef9efef6145bdc8c9c4dd1790f51673f27d\spring-boot-starter-tomcat-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework\spring-webmvc\5.3.8\2cfa5e12bf103e2c82db78ce198e455dab456465\spring-webmvc-5.3.8.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework\spring-web\5.3.8\daa288e67b0f2e09a033500d5ce8406677c5045c\spring-web-5.3.8.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.data\spring-data-commons\2.5.2\25a00968c046736667e086ed9fd254f0e26e7ffc\spring-data-commons-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework\spring-context\5.3.8\c367a05423e963c222e38a6a88b97d44de3880ca\spring-context-5.3.8.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework\spring-aop\5.3.8\1377f80f938b1fc7eabe9e6c4f6895e77e3bec40\spring-aop-5.3.8.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework\spring-orm\5.3.8\bac8889d4621f2f47ee2b118ebbddf61dd299239\spring-orm-5.3.8.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework\spring-tx\5.3.8\3202859a7e9560110f1fe8284c28feb009c6f460\spring-tx-5.3.8.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework\spring-beans\5.3.8\3d66fed1eebfcd119efcabc6218c813700a21ed\spring-beans-5.3.8.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework\spring-core\5.3.8\da9b87dacaa5bbf80fad0f7b483988372a00a152\spring-core-5.3.8.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\com.zaxxer\HikariCP\4.0.3\107cbdf0db6780a065f895ae9d8fbf3bb0e1c21f\HikariCP-4.0.3.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework\spring-jdbc\5.3.8\cf8b7a2be3565eed94f575ae640e22d9357c7dcd\spring-jdbc-5.3.8.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.aspectj\aspectjweaver\1.9.6\ee3b73aa16df35179255f17354d9dfd8e7822835\aspectjweaver-1.9.6.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.hibernate.common\hibernate-commons-annotations\5.1.2.Final\e59ffdbc6ad09eeb33507b39ffcf287679a498c8\hibernate-commons-annotations-5.1.2.Final.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.jboss.logging\jboss-logging\3.4.2.Final\e517b8a93dd9962ed5481345e4d262fdd47c4217\jboss-logging-3.4.2.Final.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.javassist\javassist\3.27.0-GA\f63e6aa899e15eca8fdaa402a79af4c417252213\javassist-3.27.0-GA.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\net.bytebuddy\byte-buddy\1.10.22\ef45d7e2cd1c600d279704f492ed5ce2ceb6cdb5\byte-buddy-1.10.22.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\antlr\antlr\2.7.7\83cd2cd674a217ade95a4bb83a8a14f351f48bd0\antlr-2.7.7.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.jboss\jandex\2.2.3.Final\d3865101f0666b63586683bd811d754517f331ab\jandex-2.2.3.Final.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\com.fasterxml\classmate\1.5.1\3fe0bed568c62df5e89f4f174c101eab25345b6c\classmate-1.5.1.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.dom4j\dom4j\2.1.3\a75914155a9f5808963170ec20653668a2ffd2fd\dom4j-2.1.3.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.glassfish.jaxb\jaxb-runtime\2.3.4\5f3828d3a345ff3d8acb83f07ba04eccf59e15bb\jaxb-runtime-2.3.4.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.thymeleaf\thymeleaf\3.0.12.RELEASE\de1865b0d58590a50c33900115a293335dd8ef25\thymeleaf-3.0.12.RELEASE.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-logging\2.5.2\8b94a1e350f68f8c3a7de6460e5691a84c8c157d\spring-boot-starter-logging-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-autoconfigure\2.5.2\aa924c5d0d375f4b2b66f211704c24d40a7e647b\spring-boot-autoconfigure-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot\2.5.2\bd6dc87b5ad870dbf635d0c7d9a3006666c9e797\spring-boot-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\jakarta.annotation\jakarta.annotation-api\1.3.5\59eb84ee0d616332ff44aba065f3888cf002cd2d\jakarta.annotation-api-1.3.5.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.yaml\snakeyaml\1.28\7cae037c3014350c923776548e71c9feb7a69259\snakeyaml-1.28.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jdk8\2.12.3\77424ea087313312e308dae5ff8445608aabb5e1\jackson-datatype-jdk8-2.12.3.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jsr310\2.12.3\f69c636438dcf19c49960c1fe8901320ab85f989\jackson-datatype-jsr310-2.12.3.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.module\jackson-module-parameter-names\2.12.3\592a882beaf1bd57b8fe960b937a2706b090b4d7\jackson-module-parameter-names-2.12.3.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.12.3\d6153f8fc60c479ab0f9efb35c034526436a4953\jackson-databind-2.12.3.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-websocket\9.0.48\a34e3133ec3d61f4c2faa30476c4b43cc6385dd6\tomcat-embed-websocket-9.0.48.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-core\9.0.48\f112cd2380d8215e22ac40aff128a1b6daa2f0ac\tomcat-embed-core-9.0.48.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-el\9.0.48\c46a092831493ccf65674cb19235625853ceb3d4\tomcat-embed-el-9.0.48.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework\spring-expression\5.3.8\8a14547b76cbae3aeb02739e5b38e71835a6bbd8\spring-expression-5.3.8.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework\spring-jcl\5.3.8\a143c8618eb2be8674c3cf132d9a5c953bb5488\spring-jcl-5.3.8.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\jakarta.xml.bind\jakarta.xml.bind-api\2.3.3\48e3b9cfc10752fba3521d6511f4165bea951801\jakarta.xml.bind-api-2.3.3.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.glassfish.jaxb\txw2\2.3.4\257fa649d3137a1060d222aefb96b7d1dd5f1286\txw2-2.3.4.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\com.sun.istack\istack-commons-runtime\3.0.12\cbbe1a62b0cc6c85972e99d52aaee350153dc530\istack-commons-runtime-3.0.12.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.attoparser\attoparser\2.0.5.RELEASE\a93ad36df9560de3a5312c1d14f69d938099fa64\attoparser-2.0.5.RELEASE.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.unbescape\unbescape\1.1.6.RELEASE\7b90360afb2b860e09e8347112800d12c12b2a13\unbescape-1.1.6.RELEASE.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-classic\1.2.3\7c4f3c474fb2c041d8028740440937705ebb473a\logback-classic-1.2.3.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-to-slf4j\2.14.1\ce8a86a3f50a4304749828ce68e7478cafbc8039\log4j-to-slf4j-2.14.1.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.slf4j\jul-to-slf4j\1.7.31\f9ff62d83a25a94c1619de06d4015e2797bc849c\jul-to-slf4j-1.7.31.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.12.3\7275513412694a1aafd08c0287f48469fa0e6e17\jackson-annotations-2.12.3.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-core\1.2.3\864344400c3d4d92dfeb0a305dc87d953677c03c\logback-core-1.2.3.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-api\2.14.1\cd8858fbbde69f46bce8db1152c18a43328aae78\log4j-api-2.14.1.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-devtools\2.5.2\bac97c59586c4afcf80c65fb7ea22085f9b29991\spring-boot-devtools-2.5.2.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\mysql\mysql-connector-java\8.0.25\f8b9123acd13058c941aff25f308c9ed8000bb73\mysql-connector-java-8.0.25.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.webjars\bootstrap\4.5.0\80c472598acca90a848e35731f95d2f806617c58\bootstrap-4.5.0.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.webjars\jquery\3.5.1\2392938e374f561c27c53872bdc9b6b351b6ba34\jquery-3.5.1.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\org.webjars\popper.js\1.16.0\6fafd6e11cd1fb6f09cf769aa031d421ea26c619\popper.js-1.16.0.jar;C:\Users\131ji\.gradle\caches\modules-2\files-2.1\com.sun.activation\jakarta.activation\1.2.2\74548703f9851017ce2f556066659438019e7eb5\jakarta.activation-1.2.2.jar net.codejava.InventoryApp.InventoryAppApplication
 
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '| '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.5.2)
 
2021-07-05 15:06:16.345  INFO 4468 --- [  restartedMain] n.c.I.InventoryAppApplication            : Starting InventoryAppApplication using Java 11.0.7 on LAPTOP-I28PJHTD with PID 4468 (D:\Programs\InventoryApp\InventoryApp\out\production\classes started by 131ji in D:\Programs\InventoryApp\InventoryApp)
2021-07-05 15:06:16.348  INFO 4468 --- [  restartedMain] n.c.I.InventoryAppApplication            : No active profile set, falling back to default profiles: default
2021-07-05 15:06:16.424  INFO 4468 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2021-07-05 15:06:16.424  INFO 4468 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2021-07-05 15:06:17.603  INFO 4468 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-07-05 15:06:17.615  INFO 4468 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-07-05 15:06:17.616  INFO 4468 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.48]
2021-07-05 15:06:17.744  INFO 4468 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-07-05 15:06:17.745  INFO 4468 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1320 ms
2021-07-05 15:06:17.796  WARN 4468 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'categoryController': Unsatisfied dependency expressed through field 'categoryRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'net.codejava.InventoryApp.category.CategoryRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2021-07-05 15:06:17.799  INFO 4468 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-07-05 15:06:17.820  INFO 4468 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 
 
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-07-05 15:06:17.839 ERROR 4468 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 
 
***************************
APPLICATION FAILED TO START
***************************
 
Description:
 
Field categoryRepository in net.codejava.InventoryApp.category.CategoryController required a bean of type 'net.codejava.InventoryApp.category.CategoryRepository' that could not be found.
 
The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)
 
 
Action: //여기를 눈 여겨 볼 것
 
Consider defining a bean of type 'net.codejava.InventoryApp.category.CategoryRepository' in your configuration.
 
 
Process finished with exit code 0
 
cs

 

 

 

[기존 - 오류 발생 때 application]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package net.codejava.InventoryApp;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
public class InventoryAppApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(InventoryAppApplication.class, args);
    }
 
}
 
cs

 

 

 

[해결 - application 정상 작동]

1
2
3
4
5
6
7
8
9
10
package net.codejava.InventoryApp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

//scanBasePackages에서 경로 지정
@SpringBootApplication(scanBasePackages = {"net.codejava.InventoryApp"})
public class InventoryAppApplication {
    public static void main(String[] args) {
        SpringApplication.run(InventoryAppApplication.class, args);
    }
}
cs