Spring bean scopes example

2015-08-20  本文已影响11人  lovePython
<?xml version="1.0"?>
<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-2.5.xsd">
    <bean id="customerService" class="com.mkyong.customer.services.CustomerService" scope="prototype" />
</beans>
package com.mkyong.customer.services;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
@Service
@Scope("prototype")
public class CustomerService { 
    String message; 
    public String getMessage() { 
        return message; 
    } 
   public void setMessage(String message) { 
        this.message = message; 
    }
}
<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    <context:component-scan base-package="com.mkyong.customer" />
</beans>
上一篇 下一篇

猜你喜欢

热点阅读