Skip to content

Commit ee9152a

Browse files
Euniceaduzhendrikse
authored andcommitted
BAEL-1014 [Spring MVC with Kotlin] (eugenp#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 74447a1. * 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
1 parent 04689cc commit ee9152a

7 files changed

Lines changed: 191 additions & 0 deletions

File tree

‎pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
<module>spring-mvc-webflow</module>
176176
<module>spring-mvc-xml</module>
177177
<module>spring-mvc-simple</module>
178+
<module>spring-mvc-kotlin</module>
178179
<module>spring-security-openid</module>
179180
<module>spring-protobuf</module>
180181
<module>spring-quartz</module>

‎spring-mvc-kotlin/pom.xml‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.baeldung</groupId>
9+
<artifactId>parent-modules</artifactId>
10+
<version>1.0.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>spring-mvc-kotlin</artifactId>
14+
<version>0.1-SNAPSHOT</version>
15+
16+
<name>spring-mvc-kotlin</name>
17+
18+
<packaging>war</packaging>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.jetbrains.kotlin</groupId>
23+
<artifactId>kotlin-stdlib-jre8</artifactId>
24+
<version>1.1.4</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.jetbrains.kotlin</groupId>
28+
<artifactId>kotlin-reflect</artifactId>
29+
<version>1.1.4</version>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.springframework</groupId>
34+
<artifactId>spring-web</artifactId>
35+
<version>4.3.10.RELEASE</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework</groupId>
39+
<artifactId>spring-webmvc</artifactId>
40+
<version>4.3.10.RELEASE</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>javax.servlet</groupId>
44+
<artifactId>jstl</artifactId>
45+
<version>1.2</version>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
51+
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
52+
<plugins>
53+
<plugin>
54+
<artifactId>kotlin-maven-plugin</artifactId>
55+
<groupId>org.jetbrains.kotlin</groupId>
56+
<version>1.1.4</version>
57+
58+
<executions>
59+
<execution>
60+
<id>compile</id>
61+
<phase>compile</phase>
62+
<goals>
63+
<goal>compile</goal>
64+
</goals>
65+
</execution>
66+
67+
<execution>
68+
<id>test-compile</id>
69+
<phase>test-compile</phase>
70+
<goals>
71+
<goal>test-compile</goal>
72+
</goals>
73+
</execution>
74+
</executions>
75+
</plugin>
76+
</plugins>
77+
</build>
78+
79+
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.baeldung.kotlin.mvc
2+
3+
import org.springframework.context.annotation.Bean
4+
import org.springframework.context.annotation.Configuration
5+
import org.springframework.web.servlet.ViewResolver
6+
import org.springframework.web.servlet.config.annotation.EnableWebMvc
7+
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
8+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
9+
import org.springframework.web.servlet.view.InternalResourceViewResolver
10+
import org.springframework.web.servlet.view.JstlView
11+
12+
13+
14+
15+
16+
@EnableWebMvc
17+
@Configuration
18+
open class ApplicationWebConfig: WebMvcConfigurerAdapter() {
19+
20+
override fun addViewControllers(registry: ViewControllerRegistry?) {
21+
super.addViewControllers(registry)
22+
23+
registry!!.addViewController("/welcome.html")
24+
}
25+
26+
@Bean
27+
open fun viewResolver(): ViewResolver {
28+
val bean = InternalResourceViewResolver()
29+
30+
bean.setViewClass(JstlView::class.java)
31+
bean.setPrefix("/WEB-INF/view/")
32+
bean.setSuffix(".jsp")
33+
34+
return bean
35+
}
36+
37+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.kotlin.mvc
2+
3+
import com.baeldung.kotlin.mvc.ApplicationWebConfig
4+
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer
5+
6+
class ApplicationWebInitializer: AbstractAnnotationConfigDispatcherServletInitializer() {
7+
8+
override fun getRootConfigClasses(): Array<Class<*>>? {
9+
return null
10+
}
11+
12+
override fun getServletMappings(): Array<String> {
13+
return arrayOf("/")
14+
}
15+
16+
override fun getServletConfigClasses(): Array<Class<*>> {
17+
return arrayOf(ApplicationWebConfig::class.java)
18+
}
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<beans xmlns="http://www.springframework.org/schema/beans"
2+
xmlns:context="http://www.springframework.org/schema/context"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:mvc="http://www.springframework.org/schema/mvc"
5+
xsi:schemaLocation="
6+
http://www.springframework.org/schema/beans
7+
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
8+
http://www.springframework.org/schema/mvc
9+
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
10+
http://www.springframework.org/schema/context
11+
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
12+
13+
<context:component-scan base-package="com.baeldung.kotlin.mvc" />
14+
15+
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
16+
<property name="prefix" value="/WEB-INF/view/"/>
17+
<property name="suffix" value=".jsp"/>
18+
</bean>
19+
20+
<mvc:view-controller path="/welcome.html"/>
21+
22+
<mvc:annotation-driven />
23+
24+
</beans>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<head>Welcome</head>
3+
4+
<body>
5+
<h1>This is the body of the welcome view 2</h1>
6+
</body>
7+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xmlns="http://java.sun.com/xml/ns/javaee"
3+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
4+
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
5+
version="3.0">
6+
7+
<display-name>Spring Kotlin MVC Application</display-name>
8+
9+
<servlet>
10+
<servlet-name>spring-web-mvc</servlet-name>
11+
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
12+
<load-on-startup>1</load-on-startup>
13+
<init-param>
14+
<param-name>contextConfigLocation</param-name>
15+
<param-value>/WEB-INF/spring-web-config.xml</param-value>
16+
</init-param>
17+
</servlet>
18+
19+
<servlet-mapping>
20+
<servlet-name>spring-web-mvc</servlet-name>
21+
<url-pattern>/</url-pattern>
22+
</servlet-mapping>
23+
24+
</web-app>

0 commit comments

Comments
 (0)