답변 3
1
1
해당 부분은 영한님 강의 자료 5페이지에 설명이 되어 있어서 발췌해왔습니다.
1. 실행을 Gradle로 설정하면, tomcat 의존성을 유지
2. 실행을 IntelliJ IDEA로 설정하면, tomcat 의존성을 제거
저 또한 커뮤니티 에디션으로 테스트를 했다고 말씀 드렸는데, IntelliJ IDEA 실행에 tomcat 의존성을 유지하고도 질문자님과 같은 오류가 발생하지 않았던 이유는, ServletApplication 클래스에 @ServletComponentScan 어노테이션을 붙이지 않고 실행해서 그렇습니다. 즉, 제가 이후 단계인 HelloServlet이 정상 동작하는지까지 테스트하지 않았다는 의미죠.
영한님 강의를 따라가는 전체 흐름으로 보자면 추가로 말씀하신 문제가 충분히 발생할 수 있는데, 제가 거기까지 생각을 못 하고 질문 내용인 메인 메서드 실행에만 중점을 두고 답변을 드린 것 같아 송구합니다.
문제 해결이 잘 되셨으면 좋겠습니다.
친절한 설명 감사드리며
정리하자면 무료버전인경우 @ServletComponentScan 이 있다면 provideRuntime 을 삭제해주면 된다는 거죠 사용은 gradle로 해야하느거구 실행이 지속되는거는 어쩔수 없는거구요
한글깨지는 문제는 utf-8로 해줫는데 왜 깨지는 걸 까요?
sername=hello
age=22
[��ü �Ķ���� ��ȸ] - end
[���� �Ķ���� ��ȸ]
request.getParameter(username) = hello
request.getParameter(age) = 22
[�̸��� ���� ���� �Ķ���� ��ȸ]
request.getParameterValues(username)
username=hello
username=hello2
2021-04-11 15:52:53.626 DEBUG 27944 --- [nio-8080-exec-1] o.a.coyote.http11.Http11InputBuffer : Before fill(): [true], parsingRequestLine: [true], parsingRequestLinePhase: [0], parsingRequestLineStart: [0], byteBuffer.position() [0]
2021-04-11 15:52:53.627 DEBUG 27944 --- [nio-8080-exec-1] o.a.coyote.http11.Http11InputBuffer : Received []
2021-04-11 15:52:53.628 DEBUG 27944 --- [nio-8080-exec-1] o.apache.coyote.http11.Http11Processor : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@7e6fa219:org.apache.tomcat.util.net.NioChannel@b19893f:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8080 remote=/0:0:0:0:0:0:0:1:59079]], Status in: [OPEN_READ], State out: [OPEN]
2021-04-11 15:52:53.766 DEBUG 27944 --- [nio-8080-exec-2] o.a.coyote.http11.Http11InputBuffer : Before fill(): [true], parsingRequestLine: [true], parsingRequestLinePhase: [0], parsingRequestLineStart: [0], byteBuffer.position() [0]
2021-04-11 15:52:53.768 DEBUG 27944 --- [nio-8080-exec-2] o.a.coyote.http11.Http11InputBuffer : Received [GET /favicon.ico HTTP/1.1
Host: localhost:8080
Connection: keep-alive
sec-ch-ua: "Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36
Accept: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: no-cors
Sec-Fetch-Dest: image
Referer: http://localhost:8080/request-param?username=hello&age=22&username=hello2
Accept-Encoding: gzip, deflate, br
Accept-Language: ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7
]
2021-04-11 15:52:53.776 INFO 27944 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-04-11 15:52:53.777 INFO 27944 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2021-04-11 15:52:53.780 INFO 27944 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 3 ms
2021-04-11 15:52:54.283 DEBUG 27944 --- [nio-8080-exec-2] o.a.coyote.http11.Http11InputBuffer : Before fill(): [true], parsingRequestLine: [true], parsingRequestLinePhase: [0], parsingRequestLineStart: [0], byteBuffer.position() [0]
2021-04-11 15:52:54.284 DEBUG 27944 --- [nio-8080-exec-2] o.a.coyote.http11.Http11InputBuffer : Received []
2021-04-11 15:52:54.285 DEBUG 27944 --- [nio-8080-exec-2] o.apache.coyote.http11.Http11Processor : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@7e6fa219:org.apache.tomcat.util.net.NioChannel@b19893f:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8080 remote=/0:0:0:0:0:0:0:1:59079]], Status in: [OPEN_READ], State out: [OPEN]
1. 정리하자면 무료버전인경우 @ServletComponentScan 이 있다면 provideRuntime 을 삭제해주면 된다는 거죠 사용은 gradle로 해야하느거구 실행이 지속되는거는 어쩔수 없는거구요
→ 커뮤니티 에디션일 때 @ServletComponentScan이 있기 때문에 tomcat 의존성을 삭제하는 것은 아닙니다. 질문 내용을 정리해보자면, 첫 번째 질문처럼 프로젝트 실행 시 메인 메서드가 계속 유지되는 화면 때문에 실행을 IntelliJ IDEA로 변경했는데 이번엔 두 번째 질문처럼 실행이 안 되는 문제가 발생했으니, 추가적인 조치로 tomcat 의존성을 제거하시라고 말씀 드린 겁니다. 커뮤니티 에디션이라서 실행을 꼭 Gradle로 하실 필요는 없으며, IntelliJ IDEA 대신 Gradle로 하고 싶으시다면 실행을 Gradle로 설정하시고 tomcat 의존성을 유지하는 추가적인 옵션도 말씀 드린 거구요.
즉, 에러 발생 여부가 @ServletComponentScan 유무와는 상관이 없습니다. 다만 해당 어노테이션이 없다면 스프링이 서블릿을 자동으로 등록하지 않아 클라이언트 요청을 서블릿이 처리하지 못하겠죠(@ServletComponentScan은 제가 실행을 IntelliJ IDEA로 설정하고 tomcat 의존성을 지우지 않았는데도 두 번째 질문하신 에러가 발생하지 않았던 이유를 설명드리고자 언급한 것이었는데, 괜히 질문자님께서 이해하시는 데 혼란을 드린 거 같아서 죄송합니다). 결론적으로 Gradle을 통한 메인 메서드 실행이 유지되는 화면을 보는 걸 원하지 않으시면 실행은 IntelliJ IDEA, tomcat 의존성은 제거, 두 가지만 설정하시면 됩니다.
2. 한글 깨짐 문제
[��ü �Ķ���� ��ȸ] - end
[���� �Ķ���� ��ȸ]
request.getParameter(username) = hello
request.getParameter(age) = 22
[�̸��� ���� ���� �Ķ���� ��ȸ]
→ 한글을 출력하는 부분이 어디인지 몰라서 파악이 어려운데, 일단 프로젝트 및 파일 인코딩이 UTF-8로 잘 설정되어 있는지 확인해보시면 될 것 같습니다.
프로젝트 인코딩은 [Settings] - [Editor] - [File Encodings] 에서,
파일 인코딩은 파일을 여신 다음 우측 하단에서 확인 가능합니다.
1
안녕하세요, 사탕님.
IntelliJ에서 프로젝트 실행 시 Gradle을 통해서 실행되도록 설정이 되어 있는 것 같습니다.
해당 내용 관련 설정 방법의 출처는 영한님께서 정리하신 강의 자료 4~5페이지입니다.
아래 이미지대로 설정하시면 될 것 같습니다.
(※ 영한님 혹시 강의 자료 발췌와 관련하여 문제가 된다면 말씀해주시기 바랍니다.)
조금이나마 도움이 되었으면 좋겠습니다.
"C:\Program Files\Java\jdk-11.0.2\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.2\lib\idea_rt.jar=53971:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.2\bin" -Dfile.encoding=UTF-8 -classpath C:\study\springmvc\servlet\out\production\classes;C:\study\springmvc\servlet\out\production\resources;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-web\2.4.4\8b84b6800a0b72d644d77aea3df0bf02008096a7\spring-boot-starter-web-2.4.4.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-json\2.4.4\3f9622c37d6ece1cbf5889aee688adbcc78ddeea\spring-boot-starter-json-2.4.4.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter\2.4.4\5807f7ab098711f28d7d92c5986c6c5cfd82e996\spring-boot-starter-2.4.4.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework\spring-webmvc\5.3.5\449649af0eda09def9b5748bc8438253bf02f9f3\spring-webmvc-5.3.5.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework\spring-web\5.3.5\8233c67b3f33f619f6f8f34cc0f56e01a00e136e\spring-web-5.3.5.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jdk8\2.11.4\e1540dea3c6c681ea4e335a960f730861ee3bedb\jackson-datatype-jdk8-2.11.4.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jsr310\2.11.4\ce6fc76bba06623720e5a9308386b6ae74753f4d\jackson-datatype-jsr310-2.11.4.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.module\jackson-module-parameter-names\2.11.4\432e050d79f2282a66c320375d628f1b0842cb12\jackson-module-parameter-names-2.11.4.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.11.4\5d9f3d441f99d721b957e3497f0a6465c764fad4\jackson-databind-2.11.4.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-autoconfigure\2.4.4\6237b28c1bad51b175e5b91222292924322fda54\spring-boot-autoconfigure-2.4.4.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot\2.4.4\38392ae406009e55efe873baee4633bfa6b766b3\spring-boot-2.4.4.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-logging\2.4.4\4432cf056309ece02eb23417bc70f96b59ac8c24\spring-boot-starter-logging-2.4.4.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework\spring-core\5.3.5\633de7c79bfeccf05c81a0d4a32b3336010f06ab\spring-core-5.3.5.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.yaml\snakeyaml\1.27\359d62567480b07a679dc643f82fc926b100eed5\snakeyaml-1.27.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework\spring-context\5.3.5\15166e945c1221016a534f1aa83bbddf992dba0a\spring-context-5.3.5.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework\spring-aop\5.3.5\a52b30c37937ddb01585430bcc8442b2ac2a8b58\spring-aop-5.3.5.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework\spring-beans\5.3.5\7604a458b0d8a47cdb113cf874c21c9750b53188\spring-beans-5.3.5.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework\spring-expression\5.3.5\7149f94a2b134ffcd23cfd74f04ee1f1f2215347\spring-expression-5.3.5.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.11.4\593f7b18bab07a76767f181e2a2336135ce82cc4\jackson-core-2.11.4.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.11.4\2c3f5c079330f3a01726686a078979420f547ae4\jackson-annotations-2.11.4.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-classic\1.2.3\7c4f3c474fb2c041d8028740440937705ebb473a\logback-classic-1.2.3.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-to-slf4j\2.13.3\966f6fd1af4959d6b12bfa880121d4a2b164f857\log4j-to-slf4j-2.13.3.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.slf4j\jul-to-slf4j\1.7.30\d58bebff8cbf70ff52b59208586095f467656c30\jul-to-slf4j-1.7.30.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.springframework\spring-jcl\5.3.5\b4d8d3af78fb4e0f86534f75122e6896c37cf3f6\spring-jcl-5.3.5.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-core\1.2.3\864344400c3d4d92dfeb0a305dc87d953677c03c\logback-core-1.2.3.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\1.7.30\b5a4b6d16ab13e34a88fae84c35cd5d68cac922c\slf4j-api-1.7.30.jar;C:\Users\82109\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-api\2.13.3\ec1508160b93d274b1add34419b897bae84c6ca9\log4j-api-2.13.3.jar hello.servlet.ServletApplication
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.4)
2021-04-11 10:31:23.270 INFO 13264 --- [ main] hello.servlet.ServletApplication : Starting ServletApplication using Java 11.0.2 on DESKTOP-C6Q38EP with PID 13264 (C:\study\springmvc\servlet\out\production\classes started by 82109 in C:\study\springmvc\servlet)
2021-04-11 10:31:23.279 INFO 13264 --- [ main] hello.servlet.ServletApplication : No active profile set, falling back to default profiles: default
2021-04-11 10:31:24.588 WARN 13264 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletComponentRegisteringPostProcessor': Unexpected exception during bean creation; nested exception is java.lang.NoClassDefFoundError: javax/servlet/annotation/WebServlet
2021-04-11 10:31:24.603 INFO 13264 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-11 10:31:24.655 ERROR 13264 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletComponentRegisteringPostProcessor': Unexpected exception during bean creation; nested exception is java.lang.NoClassDefFoundError: javax/servlet/annotation/WebServlet
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-5.3.5.jar:5.3.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.5.jar:5.3.5]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.5.jar:5.3.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.5.jar:5.3.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.5.jar:5.3.5]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:196) ~[spring-context-5.3.5.jar:5.3.5]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746) ~[spring-context-5.3.5.jar:5.3.5]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564) ~[spring-context-5.3.5.jar:5.3.5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:769) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1313) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[spring-boot-2.4.4.jar:2.4.4]
at hello.servlet.ServletApplication.main(ServletApplication.java:12) ~[classes/:na]
Caused by: java.lang.NoClassDefFoundError: javax/servlet/annotation/WebServlet
at org.springframework.boot.web.servlet.WebServletHandler.<init>(WebServletHandler.java:39) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.web.servlet.ServletComponentRegisteringPostProcessor.<clinit>(ServletComponentRegisteringPostProcessor.java:49) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.web.servlet.ServletComponentScanRegistrar$ServletComponentRegisteringPostProcessorBeanDefinition.lambda$getInstanceSupplier$0(ServletComponentScanRegistrar.java:94) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1231) ~[spring-beans-5.3.5.jar:5.3.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-5.3.5.jar:5.3.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-5.3.5.jar:5.3.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.5.jar:5.3.5]
... 14 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.annotation.WebServlet
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na]
... 21 common frames omitted
Process finished with exit code 1
잘 해결하셨다니 다행입니다. 즐거운 코딩 되세요~