BAEL-1014 [Spring MVC with Kotlin] (#2459)

* 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 74447a163b.

* 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
This commit is contained in:
Eunice A. Obugyei
2017-08-19 03:08:06 +00:00
committed by Zeger Hendrikse
parent 04689cc249
commit ee9152a091
7 changed files with 191 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
package com.baeldung.kotlin.mvc
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
@EnableWebMvc
@Configuration
open class ApplicationWebConfig: WebMvcConfigurerAdapter() {
override fun addViewControllers(registry: ViewControllerRegistry?) {
super.addViewControllers(registry)
registry!!.addViewController("/welcome.html")
}
@Bean
open fun viewResolver(): ViewResolver {
val bean = InternalResourceViewResolver()
bean.setViewClass(JstlView::class.java)
bean.setPrefix("/WEB-INF/view/")
bean.setSuffix(".jsp")
return bean
}
}

View File

@@ -0,0 +1,19 @@
package com.baeldung.kotlin.mvc
import com.baeldung.kotlin.mvc.ApplicationWebConfig
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer
class ApplicationWebInitializer: AbstractAnnotationConfigDispatcherServletInitializer() {
override fun getRootConfigClasses(): Array<Class<*>>? {
return null
}
override fun getServletMappings(): Array<String> {
return arrayOf("/")
}
override fun getServletConfigClasses(): Array<Class<*>> {
return arrayOf(ApplicationWebConfig::class.java)
}
}

View File

@@ -0,0 +1,24 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<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 />
</beans>

View File

@@ -0,0 +1,7 @@
<html>
<head>Welcome</head>
<body>
<h1>This is the body of the welcome view 2</h1>
</body>
</html>

View File

@@ -0,0 +1,24 @@
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Spring Kotlin MVC Application</display-name>
<servlet>
<servlet-name>spring-web-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-web-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>spring-web-mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>