Spring MVC: properties in the Application Context VS in the Servlet Context

I was deploying a web app based on Spring MVC (3.2.6.RELEASE). In this web app I was trying to use properties in the application context as well as in the servlet context. Now, I determined experimentally (I would have to check the code to be absolutely sure) that in the application context when using missing Continue reading →

Spring-Test & Spring Security: How to mock Authentication

I was trying to figure out how to unit test if my the URLs of my controllers are properly secured. Just in case someone changes things around and accidentally removes security settings. I set up a WebTestEnvironment like so: import javax.annotation.Resource; import javax.naming.NamingException; import javax.sql.DataSource;   import org.junit.Before; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import Continue reading →

Spring AOP

Here are a few links on how to do aspect oriented programming with Spring using annotations (AspectJ). This article does explain it pretty thoroughly: Spring AOP and Annotation based AspectJ The followng code snippet is note worthy: @Around("anyPublicMethod() && @annotation(logAction)") public Object logAction(ProceedingJoinPoint pjp, LogAction logAction) throws Throwable { }@Around("anyPublicMethod() && @annotation(logAction)") public Object logAction(ProceedingJoinPoint Continue reading →

Spring: DriverManagerDataSource causes Infinite Loop using "destroy-method" Parameter

I was using the following data settings: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">   <context:property-placeholder properties-ref="deployProperties" />   <tx:annotation-driven transaction-manager="transactionManager" />   <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="mysqlDataSource"/> </bean>   <bean id="mysqlDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close"> <property name="driverClassName" Continue reading →

Spring 3: Request Mapping - Selecting Wildcard

I was using the follwing wildcard: @RequestMapping("/something/**") public requestMapping() { // ... }@RequestMapping("/something/**") public requestMapping() { // ... } And wanted to access the String matched by **. This works as follows: @RequestMapping("/something/**") public requestMapping() { String relativeUrl = (String) request.getAttribute( HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);   // ... }@RequestMapping("/something/**") public requestMapping() { String relativeUrl = (String) request.getAttribute( HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); Continue reading →

Tomcat: Servlet Context Parameters

I have been working with Tomcat and Srping and was trying to get settings from the META-INF/context.xml to be accessible in Spring or the JSPs. I found a few ways. The first one is by creating a JNDI resource using a custom bean and @Autowire it. The second involves context parameters. Custom JNDI Resource In Continue reading →