메이븐 스프링부트 프로젝트 생성 에러

최고고·2025년 4월 30일
0

백기선 센세의 스프링부트 원리 강의 따라하던 중 플젝 생성 에러가 났는데요..
일단 IDE 는 egov 3.7.0
메이븐프로젝트로로 생성했다.

✅ Spring Boot는 Maven Central 저장소에 배포되어 있다.
따라서 Maven을 사용해서 Spring Boot 의존성을 추가할 수 있다.

✅ Maven 프로젝트를 설정하려면: pom.xml 파일에 필요한 의존성을 추가해야함.

spring-boot-starter-parent는 버전 관리와 기본 설정을 제공하는 Maven 부모 POM
spring-boot-starter는 가장 기본적인 스타터(필수 기본 라이브러리 모음)
-- > 아것들이 있어야 스프링부트 프로젝트임
또한 main() 클래스에서 SpringApplication.run() 호출이 있어야 부팅됨
spring-boot-starter-parentd와 spring-boot-starter-web 의존성을 추가하고,
main() 클래스에서 SpringApplication.run()
까지 전부 설정해줌!

그러나.

☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️☠️

🔥 빌드에러 : <defaultGoal>install</defaultGoal>
태그 추가로 해결

🔥 메인클래스의 임포트 에러 @SpringBootApplication 빨간줄
spring-boot-autoconfigure 흐름에러

  1. spring-boot-starter-web 의존성 재확인
  2. 프로젝트 우클릭 → Maven → Update Project (Alt + F5)
    → Force Update of Snapshots/Releases 체크하고 OK
  3. 프로젝트 우클릭 → Build Path → Configure Build Path
    Libraries 탭에서 JRE System Library, Maven Dependencies 잘 들어있는지 확인
  4. 프로젝트 클린
    ➡️ 전부 안돼서
  • .m2 가서 repository/org/springframework/boot/spring-boot-autoconfigure 폴더 통째로 삭제하니까

➡️➡️빨간줄에러 해결 임포트 됨

🔥 메인클래스 자바 run 에러
Run As → Java Application 시 에러남
에러내용:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/classic/turbo/TurboFilter 
.
.
.

원인: 로깅(Logback) 라이브러리 누락

<dependency>
  <groupId>ch.qos.logback</groupId>
  <artifactId>logback-classic</artifactId>
  <version>1.2.3</version> 
</dependency>
  • 의존성 추가
  • 프로젝트 우클릭 → Maven → Update Project (Alt + F5) → Force Update 체크하고 OK

보통 spring-boot-starter-web 안에 spring-boot-starter-logging 이 자동 포함되는데,
뭔가 의존성 충돌/누락 때문에 logback-classic 이 정상적으로 안 들어온 것으로 추측

➡️➡️그래도 안돼서 위 방법처럼 .m2가서 캐시날리고 재빌드

전체pom.xml 코드

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>디폴트로 생성이되어있음 건드리지않음</groupId>
  <artifactId>spring-boot-getting-started</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

<!-- Inherit defaults from Spring Boot 여기서는 설정해줌 -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.3.RELEASE</version>
	</parent>


	<!-- Package as an executable jar -->
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
		<defaultGoal>install</defaultGoal>	<!-- 이거 메이븐빌드에러나서 추가해야했음 -->
	</build>
  <name>spring-boot-getting-started</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
 <!--  이거 디폴트설정임 -->
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    
    	<!-- Add typical dependencies for a web application -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.2.3</version> <!-- Spring Boot 2.0.3와 호환 -->
</dependency>
    
  </dependencies>
</project>

제대로

실행완료

0개의 댓글