BAEL-1014 [Spring MVC with Kotlin] (#2495)
* Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611] * Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611] * Removed unnecessary comment * Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611] Added Exception test cases * Applied baeldung formatter in Eclipse * Merged from https://github.com/eugenp/tutorials Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611] * Revert "Merged from https://github.com/eugenp/tutorials" This reverts commit 74447a163b9e3f244a2578315fbdb525d20cd16b. * Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611] * Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611] * Spring Security for a Java EE Application[http://jira.baeldung.com/browse/BAEL-884] * Updated spring-security version to 4.2.3.RELEASE * Added spring-mvc-kotlin module for http://jira.baeldung.com/browse/BAEL-1014 * Removed dependency for kotlin-reflect * Switched use of JSP to Thymeleaf * Switched use of JSP to Thymeleaf
This commit is contained in:
parent
cec17bdbfe
commit
d492c6f4d8
|
@ -35,9 +35,15 @@
|
|||
<version>4.3.10.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
<groupId>org.thymeleaf</groupId>
|
||||
<artifactId>thymeleaf</artifactId>
|
||||
<version>3.0.7.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.thymeleaf</groupId>
|
||||
<artifactId>thymeleaf-spring4</artifactId>
|
||||
<version>3.0.7.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
package com.baeldung.kotlin.mvc
|
||||
|
||||
import org.springframework.context.ApplicationContext
|
||||
import org.springframework.context.ApplicationContextAware
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.web.servlet.ViewResolver
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver
|
||||
import org.springframework.web.servlet.view.JstlView
|
||||
import org.thymeleaf.spring4.SpringTemplateEngine
|
||||
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver
|
||||
import org.thymeleaf.spring4.view.ThymeleafViewResolver
|
||||
import org.thymeleaf.templatemode.TemplateMode
|
||||
|
||||
|
||||
|
||||
|
@ -15,7 +18,13 @@ import org.springframework.web.servlet.view.JstlView
|
|||
|
||||
@EnableWebMvc
|
||||
@Configuration
|
||||
open class ApplicationWebConfig: WebMvcConfigurerAdapter() {
|
||||
open class ApplicationWebConfig: WebMvcConfigurerAdapter(), ApplicationContextAware {
|
||||
|
||||
private var applicationContext: ApplicationContext? = null
|
||||
|
||||
override fun setApplicationContext(applicationContext: ApplicationContext?) {
|
||||
this.applicationContext = applicationContext
|
||||
}
|
||||
|
||||
override fun addViewControllers(registry: ViewControllerRegistry?) {
|
||||
super.addViewControllers(registry)
|
||||
|
@ -24,14 +33,28 @@ open class ApplicationWebConfig: WebMvcConfigurerAdapter() {
|
|||
}
|
||||
|
||||
@Bean
|
||||
open fun viewResolver(): ViewResolver {
|
||||
val bean = InternalResourceViewResolver()
|
||||
open fun templateResolver(): SpringResourceTemplateResolver {
|
||||
val templateResolver = SpringResourceTemplateResolver()
|
||||
templateResolver.prefix = "/WEB-INF/view/"
|
||||
templateResolver.suffix = ".html"
|
||||
templateResolver.templateMode = TemplateMode.HTML
|
||||
templateResolver.setApplicationContext(this.applicationContext);
|
||||
return templateResolver
|
||||
}
|
||||
|
||||
bean.setViewClass(JstlView::class.java)
|
||||
bean.setPrefix("/WEB-INF/view/")
|
||||
bean.setSuffix(".jsp")
|
||||
@Bean
|
||||
open fun templateEngine(): SpringTemplateEngine {
|
||||
val templateEngine = SpringTemplateEngine()
|
||||
templateEngine.setTemplateResolver(templateResolver())
|
||||
return templateEngine
|
||||
}
|
||||
|
||||
return bean
|
||||
@Bean
|
||||
open fun viewResolver(): ThymeleafViewResolver {
|
||||
val viewResolver = ThymeleafViewResolver()
|
||||
viewResolver.templateEngine = templateEngine()
|
||||
viewResolver.order = 1
|
||||
return viewResolver
|
||||
}
|
||||
|
||||
}
|
|
@ -12,13 +12,26 @@
|
|||
|
||||
<context:component-scan base-package="com.baeldung.kotlin.mvc" />
|
||||
|
||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<property name="prefix" value="/WEB-INF/view/"/>
|
||||
<property name="suffix" value=".jsp"/>
|
||||
</bean>
|
||||
|
||||
<mvc:view-controller path="/welcome.html"/>
|
||||
|
||||
<mvc:annotation-driven />
|
||||
|
||||
<bean id="templateResolver"
|
||||
class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
|
||||
<property name="prefix" value="/WEB-INF/view/" />
|
||||
<property name="suffix" value=".html" />
|
||||
<property name="templateMode" value="HTML" />
|
||||
</bean>
|
||||
|
||||
<bean id="templateEngine"
|
||||
class="org.thymeleaf.spring4.SpringTemplateEngine">
|
||||
<property name="templateResolver" ref="templateResolver" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
|
||||
<property name="templateEngine" ref="templateEngine" />
|
||||
<property name="order" value="1" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
Loading…
Reference in New Issue