This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package foo; | |
| import org.springframework.context.ApplicationContextAware; | |
| public class MyBeanImpl implements ApplicationContextAware { | |
| private ApplicationContext ctx; | |
| public void setApplicationContext(ApplicationContext context) { | |
| this.ctx=context; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package foo; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| public class MyBeanImpl { | |
| @Autowired | |
| private ApplicationContext ctx; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @RequestMapping(value = "/someurl", method = RequestMethod.GET) | |
| public ModelAndView myNotSoVerboseMethod(MyRequestParams requestParams) { | |
| ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> | |
| <property name="customArgumentResolver"> | |
| <bean class="com.mycase.resolver.MyCustomResolver"/> | |
| </property> | |
| </bean> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.mycase.resolver; | |
| import org.springframework.web.context.request.*; | |
| public class MyCustomResolver implements WebArgumentResolver{ | |
| public Object resolveArgument(MethodParameter methodParam, NativeWebRequest webRequest){ | |
| //check if parameter is of your bean | |
| if (methodParam.getParameterType()==MyRequestParams.class){ | |
| MyRequestParams requestParams = new MyRequestParams(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Maven pom.xml dependency: | |
| -==-=-=-=-=-=-=-=-=-=-=-= | |
| <project> | |
| <dependencies> | |
| <dependency> | |
| <groupId>org.jangod</groupId> | |
| <artifactId>jangod</artifactId> | |
| <version>1.0-SNAPSHOT</version> | |
| </dependency> | |
| </dependencies> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <beans> | |
| <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"> | |
| <property name="driverClass" value="com.mysql.jdbc.Driver"/> | |
| <property name="url" value="jdbc:mysql://192.168.161.131/igm_social"/> | |
| <property name="username" value="user"/> | |
| <property name="password" value="pass"/> | |
| </bean> | |
| <jdbc:embedded-database id="dataSource" type="H2"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <dependencies> | |
| <dependency> | |
| <groupId>org.glassfish</groupId> | |
| <artifactId>javax.servlet</artifactId> | |
| <version>3.0</version> | |
| <scope>provided</scope> | |
| </dependency> | |
| <dependency> | |
| <groupId>org.springframework</groupId> | |
| <artifactId>spring-webmvc</artifactId> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import javax.servlet.ServletContext; | |
| import javax.servlet.ServletException; | |
| import javax.servlet.ServletRegistration.Dynamic; | |
| import org.springframework.web.WebApplicationInitializer; | |
| import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; | |
| import org.springframework.web.servlet.DispatcherServlet; | |
| public class ContextInitializer implements WebApplicationInitializer { | |
| public void onStartup(ServletContext servletContext) throws ServletException { |