feat: freemaker 설정 remark

main
Jonguk. Lim 2 years ago
parent b09c771bf2
commit a59fa237d5

@ -56,8 +56,15 @@
</repository>
<repository>
<id>local-repository</id>
<url>file://${basedir}/repo</url>
<url>file://${project.basedir}/repo</url>
</repository>
<!--
<repository>
<id>in-project-jenkins</id>
<name>custom jars-jenkins</name>
<url>file://${JENKINS_HOME}/jobs/${JOB_NAME}/workspace/lib</url>
</repository>
-->
</repositories>
<dependencies>
@ -385,6 +392,30 @@
</dependency>
<!-- freemaker -->
<!--
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-freemarker</artifactId>
<version>${org.apache.tiles.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>${org.apache.tiles.version}</version>
</dependency>
-->
<!-- freemaker -->
<!--
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker-gae</artifactId>
<version>2.3.23</version>
</dependency>
-->
<!-- Email -->
<dependency>
@ -674,6 +705,13 @@
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>com.octo.captcha</groupId>
<artifactId>jcaptcha</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/repo/com/octo/captcha/1.0/jcaptcha-1.0.jar</systemPath>
</dependency>
</dependencies>
@ -740,8 +778,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

@ -32,4 +32,14 @@ public class SampleController {
public ModelAndView findSample(){
return ResultResponse.of(sampleService.findSample());
}
@RequestMapping("/hello")
public ModelAndView hello(){
String message = "프리마커";
ModelAndView mv = new ModelAndView();
mv.setViewName("hello");
mv.addObject("message", message);
return mv;
}
}

@ -0,0 +1,65 @@
package kr.xit.framework.support.freemaker;
import java.util.ArrayList;
import java.util.List;
import org.apache.tiles.TilesContainer;
import org.apache.tiles.evaluator.AttributeEvaluatorFactory;
import org.apache.tiles.extras.complete.CompleteAutoloadTilesContainerFactory;
import org.apache.tiles.extras.complete.CompleteAutoloadTilesInitializer;
import org.apache.tiles.factory.AbstractTilesContainerFactory;
import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.ApplicationResource;
import org.apache.tiles.request.freemarker.render.FreemarkerRendererBuilder;
import org.apache.tiles.request.render.BasicRendererFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
//@Configuration
public class FreeMarkerConfig{
@Bean
public TilesConfigurer tilesConfigurer() {
String tilesDefinitionPath = "classpath*:/WEB-INF/freemarker/layout-definition/tiles-layout.xml";
TilesConfigurer tilesConfigurer = new TilesConfigurer();
tilesConfigurer.setTilesInitializer(new CompleteAutoloadTilesInitializer() {
@Override
protected AbstractTilesContainerFactory createContainerFactory(ApplicationContext context) {
// BasicTilesContainerFactory
return new CompleteAutoloadTilesContainerFactory() {
@Override
protected List<ApplicationResource> getSources(ApplicationContext applicationContext) {
List<ApplicationResource> retValue = new ArrayList<ApplicationResource>(1);
retValue.add(applicationContext.getResource(tilesDefinitionPath));
return retValue;
}
@Override
protected void registerAttributeRenderers(BasicRendererFactory rendererFactory, ApplicationContext applicationContext, TilesContainer container, AttributeEvaluatorFactory attributeEvaluatorFactory) {
super.registerAttributeRenderers(rendererFactory, applicationContext, container, attributeEvaluatorFactory);
FreemarkerRendererBuilder freemarkerRenderer = FreemarkerRendererBuilder.createInstance();
freemarkerRenderer.setApplicationContext(applicationContext);
freemarkerRenderer.setParameter("defaultEncoding", "UTF-8");
//freemarkerRenderer.setParameter("ClasspathTlds", "/META-INF/tld/tiles-jsp.tld, /META-INF/spring.tld");
//freemarkerRenderer.setParameter("autoInclude", "/WEB-INF/freemarker/common/common.ftl");
freemarkerRenderer.setParameter("NoCache", "true");
rendererFactory.registerRenderer("freemarker", freemarkerRenderer.build());
}
};
}
});
return tilesConfigurer;
}
// @Bean
// public UrlBasedViewResolver tilesViewResolver() {
// UrlBasedViewResolver urlBasedViewResolver = new UrlBasedViewResolver();
// urlBasedViewResolver.setViewClass(TilesView.class);
// urlBasedViewResolver.setRequestContextAttribute("rc");
// return urlBasedViewResolver;
// }
}

@ -22,4 +22,6 @@
<import resource="classpath:/spring/service/context-scheduling-sym-log-lgm.xml"/>
<import resource="classpath:/spring/service/context-scheduling.xml"/>
<import resource="classpath:/spring/service/context-validator.xml"/>
<!-- <import resource="classpath:/spring/service/context-freemaker.xml"/>-->
</beans>

@ -65,6 +65,18 @@
<property name="preparerFactoryClass" value="org.springframework.web.servlet.view.tiles3.SpringBeanPreparerFactory"/>
</bean>
<!-- freemaker -->
<!--
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="order" value="2" />
<property name="cache" value="true" />
<property name="suffix" value=".ftl" />
<property name="contentType" value="text/html; charset=UTF-8" />
<property name="exposeSpringMacroHelpers" value="true" />
</bean>
-->
<!-- Annotation 을 사용하지 않는 경우에 대한 MVC 처리 설정 -->
<mvc:view-controller path="/cmmn/validator.do" view-name="cmmn/validator"/>

@ -46,6 +46,7 @@
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
<context:exclude-filter type="aspectj" expression="*..ignore..*" />
</context:component-scan>

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/ftl"/>
<property name="defaultEncoding" value="UTF-8"/>
<property name="DEFAULT_INCOMPATIBLE_IMPROVEMENTS" value="2.3.23"/>
<property name="freemarkerSettings">
<map>
<entry key="template_update_delay" value="60000"/>
<entry key="auto_flush" value="false"/>
<entry key="default_encoding" value="UTF-8"/>
<entry key="whitespace_stripping" value="true"/>
</map>
</property>
</bean>
</beans>

@ -11,6 +11,7 @@
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="aspectj" expression="*..ignore..*" />
</context:component-scan>
</beans>

@ -0,0 +1,10 @@
<#ftl encoding="utf-8"/>
<html>
<head>
<title>네이바 프리마카</title>
</head>
<body>
<h1>컨트롤러의 메세지: ${message}</h1>
</body>
</html>
Loading…
Cancel
Save