Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS 

How to get a parameter from the RequestContext in Spring

// How to get a parameter from the org.springframework.webflow.execution.RequestContext in Spring framework

// Java:
String myParameter = context.getExternalContext().getRequestParameterMap().get("myParameterPath");


// JSP:
<form:select path="myParameterPath" id="myParameterId">
    ...
</form:select>


// HTML rendered as:
<select name="myParameterPath" id="myParameterId">
...
</select>

spring 应用中添加log4j 配置

// description of your code here

<!-- 定义一个key name, 这个key name 在运行时指向当前web app的根目录 --->
  <context-param>
		<param-name>webAppRootKey</param-name>
		<param-value>petstore.root</param-value>
  </context-param>
  <!-- 定义一个log4j 配置文件的路径名称 -->
  <context-param>
		<param-name>log4jConfigLocation</param-name>
		<param-value>/WEB-INF/log4j.properties</param-value>
  </context-param>
  <!-- 使用listener 配置 log4j  -->
  <listener>
		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>

testing new bean scopes with spring 2.0 - example

// scoped bean definition
	<bean id="scopedBean"
		class="org.bla.ScopedBeanImpl"
		scope="session">
		<aop:scoped-proxy />
	</bean>

// an example test case
public class ScopedBeanTest extends AbstractRequestContextFilterTestBase {

	protected String[] getConfigLocations() {
		return new String[] { "classpath:applicationContext-with-scopedBean.xml" };
	}


	@Test
	public void testScopedBean() throws Exception {

		new FilterTest(new FilterChain() {

			public void doFilter(ServletRequest arg0, ServletResponse arg1)
					throws IOException, ServletException {
				ScopedBean scopedBean = (ScopedBean) applicationContext
						.getBean("scopedBean");
				...
				/* 
				 * let the classses under test do something with your scopedBean
				 * and check if modifications are done correctly 
				 */
				...
			}

		}).run();

	}

ProxyFactoryBean

Use of spring 's ProxyFactoryBean


  <bean id="abstractDaoTarget"
        class="com.dao.impl.GenericDaoHibernateImpl" abstract="true">
    <property name="sessionFactory">
      <ref bean="sessionFactory"/>
    </property>
  </bean>
  
  <bean id="abstractDao"
        class="org.springframework.aop.framework.ProxyFactoryBean" abstract="true">
    <property name="interceptorNames">
      <list>
        <value>finderIntroductionAdvisor</value>
      </list>
    </property>
  </bean>
  
  <bean id="dao" abstract="true">
    <property name="sessionFactory">
      <ref bean="sessionFactory"/>
    </property>
  </bean>
    
  <bean id="someDao" parent="abstractDao">
    <property name="proxyInterfaces">
      <value>com.dao.SomeDao</value>
    </property>
    <property name="target">
      <bean parent="abstractDaoTarget">
        <constructor-arg>
          <value>com.domain.SomeBean</value>
        </constructor-arg>
      </bean>
    </property>
  </bean>
  
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS