From df62a3bbe70e43e0658964d1d59cf387c14bf40f Mon Sep 17 00:00:00 2001
From: Paul-Christian Volkmer <paul-christian.volkmer@mni.thm.de>
Date: Fri, 28 Dec 2012 15:02:55 +0100
Subject: [PATCH] Major changes is Spring application configuration

With this changeset the spring servlet configuration is separeted from the
application configuration. This will result in a main context and a servlet
context, holding only spring mvc information.

This change has a very nice side effekt: Spring AOP beans will be loaded
only once in application context, not a second time in mvc servlet context.
---
 .../thm/arsnova/aop/AuthorizationAdviser.java |  4 +-
 .../arsnova/controller/LoginController.java   |  6 ++-
 .../de/thm/arsnova/entities/Question.java     |  4 +-
 src/main/webapp/WEB-INF/arsnova-servlet.xml   | 54 ++++++++++++++++++-
 .../webapp/WEB-INF/spring/spring-main.xml     | 41 --------------
 5 files changed, 60 insertions(+), 49 deletions(-)

diff --git a/src/main/java/de/thm/arsnova/aop/AuthorizationAdviser.java b/src/main/java/de/thm/arsnova/aop/AuthorizationAdviser.java
index bc41e869..4e0de0df 100644
--- a/src/main/java/de/thm/arsnova/aop/AuthorizationAdviser.java
+++ b/src/main/java/de/thm/arsnova/aop/AuthorizationAdviser.java
@@ -11,7 +11,7 @@ import de.thm.arsnova.services.IUserService;
 @Aspect
 public class AuthorizationAdviser {
 
-	private static IUserService userService;
+	private IUserService userService;
 
 	public final void setUserService(final IUserService uService) {
 		userService = uService;
@@ -43,6 +43,6 @@ public class AuthorizationAdviser {
 	 */
 	@Before("execution(public * de.thm.arsnova.services.*.*(..)) && @annotation(authenticated) && this(object)")
 	public final void checkSessionMembership(final Authenticated authenticated, final Object object) {
-		/// TODO: Implement check based on session membership lists
+		/// TODO Implement check based on session membership lists
 	}
 }
diff --git a/src/main/java/de/thm/arsnova/controller/LoginController.java b/src/main/java/de/thm/arsnova/controller/LoginController.java
index 9bbe7830..6bd7920b 100644
--- a/src/main/java/de/thm/arsnova/controller/LoginController.java
+++ b/src/main/java/de/thm/arsnova/controller/LoginController.java
@@ -104,8 +104,10 @@ public class LoginController extends AbstractController {
 			} else {
 				username = "Guest" + Sha512DigestUtils.shaHex(request.getSession().getId()).substring(0, 10);
 			}
-			org.springframework.security.core.userdetails.User user = new org.springframework.security.core.userdetails.User(
-					username, "", true, true, true, true, authorities);
+			org.springframework.security.core.userdetails.User user = 
+					new org.springframework.security.core.userdetails.User(
+							username, "", true, true, true, true, authorities
+					);
 			Authentication token = new UsernamePasswordAuthenticationToken(user, null, authorities);
 
 			SecurityContextHolder.getContext().setAuthentication(token);
diff --git a/src/main/java/de/thm/arsnova/entities/Question.java b/src/main/java/de/thm/arsnova/entities/Question.java
index e10266e9..0cc4256a 100644
--- a/src/main/java/de/thm/arsnova/entities/Question.java
+++ b/src/main/java/de/thm/arsnova/entities/Question.java
@@ -159,7 +159,7 @@ public class Question {
 
 	@Override
 	public final String toString() {
-		return "Question type '" + this.type + "': " + this.subject + ";\n" + this.text +
-				this.possibleAnswers;
+		return "Question type '" + this.type + "': " + this.subject + ";\n" 
+				+ this.text	+ this.possibleAnswers;
 	}
 }
diff --git a/src/main/webapp/WEB-INF/arsnova-servlet.xml b/src/main/webapp/WEB-INF/arsnova-servlet.xml
index 6a17391e..f5917fbb 100644
--- a/src/main/webapp/WEB-INF/arsnova-servlet.xml
+++ b/src/main/webapp/WEB-INF/arsnova-servlet.xml
@@ -1,8 +1,58 @@
 <?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-3.1.xsd">
+	xmlns:aop="http://www.springframework.org/schema/aop"
+	xmlns:mvc="http://www.springframework.org/schema/mvc"
+	xmlns:context="http://www.springframework.org/schema/context"
+	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
+		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
+		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
 
-	<!-- ARSnova Root Context: defines shared resources visible to all OTHER web components -->
+	<!-- ARSnova Servlet Context -->
+	
+	<context:component-scan base-package="de.thm.arsnova.controller" />
+	<context:annotation-config />
+	
+	<aop:aspectj-autoproxy>
+		<aop:include name="authorizationAdviser" />
+	</aop:aspectj-autoproxy>
+
+	<mvc:annotation-driven />
+	<mvc:resources mapping="/**" location="/" />
+	
+	<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
+	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
+		<property name="messageConverters">
+			<list>
+				<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
+			</list>
+		</property>
+	</bean>
+
+	<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
+		<property name="mediaTypes">
+			<map>
+			 	<entry key="html" value="text/html"/>  
+				<entry key="json" value="application/json" />
+			</map>
+		</property>
+		<property name="viewResolvers">  
+			<list>  
+				<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">  
+					<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>  
+					<property name="prefix" value="/WEB-INF/jsp/"/>  
+					<property name="suffix" value=".jsp"/>  
+				</bean>  
+		    </list>  
+		</property>  
+		<property name="defaultViews">  
+			<list>  
+				<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">  
+					<property name="prefixJson" value="false"/>  
+				</bean>  
+			</list>  
+		</property>  
+	</bean>
 	
 </beans>
diff --git a/src/main/webapp/WEB-INF/spring/spring-main.xml b/src/main/webapp/WEB-INF/spring/spring-main.xml
index f6cce1fc..c4c06e25 100644
--- a/src/main/webapp/WEB-INF/spring/spring-main.xml
+++ b/src/main/webapp/WEB-INF/spring/spring-main.xml
@@ -30,48 +30,7 @@
 	<context:component-scan base-package="de.thm.arsnova" />
 	<context:annotation-config />
 
-	<aop:aspectj-autoproxy>
-		<aop:include name="authorizationAdviser" />
-	</aop:aspectj-autoproxy>
-
-	<mvc:annotation-driven />
-	<mvc:resources mapping="/**" location="/" />
-
 	<task:annotation-driven />
-	
-	<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
-	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
-		<property name="messageConverters">
-			<list>
-				<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
-			</list>
-		</property>
-	</bean>
-
-	<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
-		<property name="mediaTypes">
-			<map>
-			 	<entry key="html" value="text/html"/>  
-				<entry key="json" value="application/json" />
-			</map>
-		</property>
-		<property name="viewResolvers">  
-			<list>  
-				<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">  
-					<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>  
-					<property name="prefix" value="/WEB-INF/jsp/"/>  
-					<property name="suffix" value=".jsp"/>  
-				</bean>  
-		    </list>  
-		</property>  
-		<property name="defaultViews">  
-			<list>  
-				<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">  
-					<property name="prefixJson" value="false"/>  
-				</bean>  
-			</list>  
-		</property>  
-	</bean>  
 
 	<bean id="socketServer" class="de.thm.arsnova.socket.ARSnovaSocketIOServer"
 		init-method="startServer" destroy-method="stopServer" scope="singleton"
-- 
GitLab