인프런 커뮤니티 질문&답변

성훈배님의 프로필 이미지
성훈배

작성한 질문수

스프링 MVC 1편 - 백엔드 웹 개발 핵심 기술

HTTP 응답 데이터 - API JSON

cannot find symbol method setUsername(String) 에러

작성

·

632

0

학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요.

1. 강의 내용과 관련된 질문을 남겨주세요.
2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요.
(자주 하는 질문 링크: https://bit.ly/3fX6ygx)
3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요.
(질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG)

질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요.
=========================================
[질문 템플릿]
1. 강의 내용과 관련된 질문인가요? (예/아니오)
2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오)
3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오)

[질문 내용]
package com.example.myproject.home;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class HelloData {
private String username;
private int age;

}
해당처럼 사용해 주었고 디렉토리는 basic -> home으로 개인적으로 바꿔줬습니다.
 

HelloData helloData = new HelloData();
helloData.setUsername("bae");
helloData.setAge(26);
하지만 이 부분에서 에러가 납니다.
 
helloData.setUsername("bae"); ^ symbol: method setUsername(String) location: variable helloData of type HelloData
 

답변 1

0

안녕하세요. 성훈배 님, 공식 서포터즈 OMG입니다.

동일한 상황이 재현 되어 해결하여 제가 해결한 방법을 설명드립니다.

1.  Enable annotation processing 체크 표시

 

2. 롬복 관련 의존성 아래 드래그 한 2줄 코드로 변경 -> 변경 후 코끼리 버튼 클릭하여 reload

해결되지 않을 경우 댓글 남겨주세요.


감사합니다.

성훈배님의 프로필 이미지
성훈배
질문자

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.projectlombok:lombok:1.18.20'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation('org.projectlombok:lombok')
annotationProcessor('org.projectlombok:lombok')
}

다시 톰캣 에러가 나네요...

 :: Spring Boot ::                (v2.6.3)

 

2022-03-15 11:11:25.127  INFO 40292 --- [           main] c.e.myproject.MyprojectApplication       : Starting MyprojectApplication using Java 11.0.13 on LAPTOP-0VRU1PJK with PID 40292 (C:\Users\qotjd\OneDrive\Desktop\study\servlet\myproject\build\classes\java\main started by qotjd in C:\Users\qotjd\OneDrive\Desktop\study\servlet\myproject)

2022-03-15 11:11:25.129  INFO 40292 --- [           main] c.e.myproject.MyprojectApplication       : No active profile set, falling back to default profiles: default

2022-03-15 11:11:25.872  INFO 40292 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (http)

2022-03-15 11:11:25.880  INFO 40292 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]

2022-03-15 11:11:25.880  INFO 40292 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.56]

2022-03-15 11:11:25.953  INFO 40292 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext

2022-03-15 11:11:25.953  INFO 40292 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 779 ms

2022-03-15 11:11:25.993 ERROR 40292 --- [           main] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: java.lang.IllegalArgumentException. Message: Invalid <url-pattern> [response-json] in servlet mapping

2022-03-15 11:11:26.009  INFO 40292 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]

2022-03-15 11:11:26.015  WARN 40292 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat

2022-03-15 11:11:26.022  INFO 40292 --- [           main] ConditionEvaluationReportLoggingListener : 

 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2022-03-15 11:11:26.044 ERROR 40292 --- [           main] o.s.boot.SpringApplication               : Application run failed

 

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:163) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[spring-context-5.3.15.jar:5.3.15]

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:414) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.6.3.jar:2.6.3]

at com.example.myproject.MyprojectApplication.main(MyprojectApplication.java:12) ~[main/:na]

Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat

at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:478) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160) ~[spring-boot-2.6.3.jar:2.6.3]

... 8 common frames omitted

Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> [response-json] in servlet mapping

at org.apache.catalina.core.StandardContext.addServletMappingDecoded(StandardContext.java:3233) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.Context.addServletMappingDecoded(Context.java:905) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.core.ApplicationServletRegistration.addMapping(ApplicationServletRegistration.java:193) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.springframework.boot.web.servlet.ServletRegistrationBean.configure(ServletRegistrationBean.java:194) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.web.servlet.ServletRegistrationBean.configure(ServletRegistrationBean.java:51) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.web.servlet.DynamicRegistrationBean.register(DynamicRegistrationBean.java:113) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.web.servlet.RegistrationBean.onStartup(RegistrationBean.java:53) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:235) ~[spring-boot-2.6.3.jar:2.6.3]

at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53) ~[spring-boot-2.6.3.jar:2.6.3]

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5219) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]

at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140) ~[na:na]

at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]

at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140) ~[na:na]

at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486) ~[tomcat-embed-core-9.0.56.jar:9.0.56]

at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) ~[spring-boot-2.6.3.jar:2.6.3]

... 13 common frames omitted

 

 

Process finished with exit code 1

https://bit.ly/3fX6ygx를 참고하여 프로젝트 압축 후 구글 드라이브에 업로드 후 링크를 공유해주세요.

코드 확인해봐야 할 것 같습니다.

성훈배님의 프로필 이미지
성훈배

작성한 질문수

질문하기