Skip to content

Instantly share code, notes, and snippets.

@igm
igm / MyController.java
Created September 23, 2011 09:16
Spring mvc controller after refactoring
@RequestMapping(value = "/someurl", method = RequestMethod.GET)
public ModelAndView myNotSoVerboseMethod(MyRequestParams requestParams) {
...
}
@igm
igm / MyController.java
Created September 23, 2011 09:12
Spring mvc Controller with many paramaters
package foo.bar;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class MyContoller{
...
@RequestMapping(value = "/someurl", method = RequestMethod.GET)
package foo;
import org.springframework.beans.factory.annotation.Autowired;
public class MyBeanImpl {
@Autowired
private ApplicationContext ctx;
}
@igm
igm / MyBeanImpl.java
Created August 24, 2011 12:51
Implementing ApplicationContextAware
package foo;
import org.springframework.context.ApplicationContextAware;
public class MyBeanImpl implements ApplicationContextAware {
private ApplicationContext ctx;
public void setApplicationContext(ApplicationContext context) {
this.ctx=context;
}
@igm
igm / MyContextInitializer.java
Created August 17, 2011 09:26
KB_spring_profile
package foo.bar;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
public class MyContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment springEnvironment = applicationContext.getEnvironment();
<web-app>
..
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextInitializerClasses</param-name>
<param-value>foo.bar.MyContextInitializer</param-value>
</init-param>
</servlet>
package foo.bar;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
public class MyContextInitializer implements
ApplicationContextInitializer<ConfigurableApplicationContext> {
private static final String PROP = "com.google.appengine.runtime.environment";
<web-app>
...
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>spring.profiles.active</param-name>
<param-value>production</param-value>
</init-param>
</servlet>
{% extends "base.html" %}
{% block content %}
<div id="part-content">
{% if posts %}
{% for post in posts %}
<div id="post-{{post.id}}" class="post-home">
<div class="post-title">
<h1><a href="{{post.link}}" rel="bookmark">{{post.title}}</a></h1>
</div>
<div class="post-content">{{post.preview}}</div>
<beans>
...
<bean id="jangodConf"
class="org.springframework.web.servlet.view.jangod.JangodConfigurer">
<property name="configurationFile" value="jangod.config.properties" />
</bean>
<bean class="org.springframework.web.servlet.view.jangod.JangodViewResolver">
<property name="jangodConfig" ref="jangodConf" />
<property name="prefix" value="/WEB-INF/views" />
<property name="suffix" value=".html" />