Spring 3.0 with JUnit Test 4


Reference URLs:

  1. https://yuangaopeng.com/2018/12/05/Spring%20Testing%20classpath/
  2. https://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#integration-testing-annotations




For JUnit test with spring, either you load context configuration:

  1. manual parse xml [ApplicationContext _ctx = ClassPathXmlApplicationContext( "abc/xyz/spring-context-all.xml" ) ], access beans via _ctx.getBean()
  2. or annotation to let spring auto wired all your attributes of test cases.



And using annotation of @ContextConfiguration, I've preference to use classpath for reasons below:

  1. Spring JUnit test cases able to share xml info.
  2. multi developer environment competible.











Enable Spring Security Web Expression(JSTL)



Reference URL:

  1. https://stackoverflow.com/questions/11594104/spring-security-no-visible-websecurityexpressionhandler-instance-could-be-foun
  2. https://www.codesd.com/item/no-webapplicationcontext-found-no-contextloaderlistener.html




Added bean configuration below into applicationContext.xml to enable Spring EL

<bean id="webexpressionHandler" class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler" />



To have this applicationContext.xml to be pickup, make sure listener has been added into /WEB-INF/web.xml


<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>