---
title: "Spring"
author: "asran"
date: "2010-12-22T13:25:41Z"
tags: []
categories: ["企业架构"]
slug: "spring"
draft: false
lastmod: "2010-12-22T13:25:41Z"
id: 849256
url: "https://asran.iteye.com/blog/849256"
---

1\. @Autowired vs. setter

@Autowired can mark in field or setter, with @Autowired, setter is not necessary;

If @Autowired is not apply to property, then setter is necesary for injection.

 

2\. @Controller, @Service, @Repository, @Component

    &lt;context:annotation-config /&gt;

    &lt;context:component-scan base-package="hk.com.mtr" /&gt;

 

3\. org.springframework.beans.factory.config.PropertyPlaceholderConfigurer

    We can't define 'propertyConfigurer' bean in 'eanRefContext.xml', define it in normal applicationContext.xml

 

4\. define properties bean:

&lt;util:properties id="jdbcProperties" location="classpath:org/example/config/jdbc.properties"/&gt;

 

5\. Spring integrate with Seam:

faces-config.xml

\--------------------------------------------------------------------------------

&lt;application&gt;

    &lt;variable-resolver&gt;org.springframework.web.jsf.DelegatingVariableResolver&lt;/variable-resolver&gt;

&lt;/application&gt;

 

components.xml

\--------------------------------------------------------------------------------

&lt;spring:context-loader config-locations="/WEB-INF/applicationContext.xml"/&gt;

 

\*\*\*.java

\--------------------------------------------------------------------------------

@In("#{bookingService}")

private BookingService bookingService;

 

applicationContext.xml

\--------------------------------------------------------------------------------

&lt;jee:jndi-lookup id="securityFacade" expected-type="hk.com.mtr.trs.facade.sa.SecurityFacade" jndi-name="hk.com.mtr.trs.facade.sa.SecurityFacade" environment-ref="jndiConfig"/&gt;

 

&lt;bean id="someSpringBean" class="SomeSpringBeanClass" scope="prototype"&gt;

    &lt;seam:component/&gt;

&lt;/bean&gt;

 

6\. Spring integrate with EJB3:

put beanRefContext.xml in classpath root:

\--------------------------------------------------------------------------------

&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;

 

    &lt;bean id="businessBeanFactory" class="org.springframework.context.support.ClassPathXmlApplicationContext"&gt;

        &lt;constructor-arg value="spring/applicationContext.xml" /&gt;

    &lt;/bean&gt;

&lt;/beans&gt;

 

\*\*\*\*.java

\--------------------------------------------------------------------------------

@Local

@Stateless

@Interceptors(SpringBeanAutowiringInterceptor.class)

public class EmailNotificationServiceImpl implements EmailNotificationService {

 

    @Autowired

    private EmailNotificationDelegate emailNotificationDelegate;

}