JudeR
20
2020-11-30 15:02:09 작성 2020-11-30 15:05:27 수정됨
2
132

Spring boot 컨트롤러에서 mustache뷰에 접근을 못하는것 같습니다 도와주세요...


spring boot에서 내장서버를 톰캣 -> undertow로 바꾼뒤 mustache 템플릿엔진을 사용해서 컨트롤러가 제대로 동작되는지만 확인하려고 단순한 페이지를 하나 만들어서 uri로 접근하려고 하는데

컨트롤러에서 uri받는것 까지는 문제가 없지만 파일내용을 보여주는게 아니라 return 내에 있는 문자열만 화면에 출력합니다. 파일로 제대로 접근하려면 어떻게 수정을 해야할까요...



현재 설정은 이렇습니다.


pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.4.0</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.jude.mission1</groupId>
	<artifactId>mission1</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>Mission1</name>
	<description>mission1 jude</description>

	<properties>
		<java.version>11</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-tomcat</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mustache -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-mustache</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>

		<dependency>
			<groupId>com.oracle.database.jdbc</groupId>
			<artifactId>ojdbc8</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.security</groupId>
			<artifactId>spring-security-test</artifactId>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-undertow</artifactId>
		</dependency>
		<!-- <dependency> <groupId>io.undertow</groupId> <artifactId>undertow-core</artifactId> 
			<version>2.1.0.Final</version> </dependency> <dependency> <groupId>io.undertow</groupId> 
			<artifactId>undertow-servlet</artifactId> <version>2.1.0.Final</version> 
			</dependency> <dependency> <groupId>io.undertow</groupId> <artifactId>undertow-websockets-jsr</artifactId> 
			<version>2.1.0.Final</version> </dependency> -->
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>


application.properties


spring.mustache.expose-session-attributes=true
spring.mustache.suffix=.html
#spring.mustache.prefix=classpath:/templates

server.port=8888


main.html


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<p>Hello World</p>
</body>
</html>


application.java


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;

@SpringBootApplication(exclude = { SecurityAutoConfiguration.class })
public class Application {
	
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}

}


RootController.java


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/")
public class RootController {
	private static final Logger log = LoggerFactory.getLogger(RootController.class);
	
	@GetMapping("/")
	public String main() {
		log.info("get...main");
		return "main";
	}
	
	@GetMapping("/index")
	public String index()	{
		log.info("get...index");
		return "index";
	}
}



0
  • 답변 2

  • 냉동참치
    640
    2020-11-30 15:15:48

    @RestController 로 하시면 리턴이 @ResponseBody로 자동으로 변환되지 않나영

  • JudeR
    20
    2020-11-30 15:17:22

    냉동참치 그렇네요...그냥 @Controller로 했더니 제대로 화면 나옵니다 감사합니당

  • 로그인을 하시면 답변 을 등록할 수 있습니다.