美文网首页
Spring bean scopes example

Spring bean scopes example

作者: lovePython | 来源:发表于2015-08-20 11:45 被阅读11次
<?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>

相关文章

网友评论

      本文标题:Spring bean scopes example

      本文链接:https://www.haomeiwen.com/subject/uzdgqttx.html