JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java Application Framework » Spring  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 請問 <ref /> 能 ref 到 JDK 已有的物件嗎? ex: java.util.Locale.TAIWAN
konasJSP





發文: 160
積分: 0
於 2007-05-01 21:35 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問

<bean>...</bean> 可以 ref java.util.Locale.TAIWAN嗎
<list>...</list> 內可以 ref java.util.Locale.TAIWAN 嗎

要如何寫呢


reply to postreply to post
作者 Re:請問 <ref /> 能 ref 到 JDK 已有的物件嗎? ex: java.util.Locale.TAIWAN [Re:konasJSP]
qrtt1





發文: 1747
積分: 31
於 2007-05-16 16:50 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
konasJSP wrote:
請問

<bean>...</bean> 可以 ref java.util.Locale.TAIWAN嗎
<list>...</list> 內可以 ref java.util.Locale.TAIWAN 嗎

要如何寫呢


注入 static object 可以想想 jdbc driver 的注入方式,模仿

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 
<beans default-autowire="autodetect">
    
    <bean id="myBean" class="foo.bar.MyBean">
      <property name="locale" value="java.util.Locale.TAIWAN" />
    </bean>
  
</beans>
 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package foo.bar;
 
import java.util.Locale;
 
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
 
public class MyBean {
  
  private Locale locale;
  
  public Locale getLocale() {
    return locale;
  }
 
  public void setLocale(Locale locale) {
    this.locale = locale;
  }
 
  public String toString() {
    return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
        .append("locale", locale).toString();
  }
  
  public static void main(String[] args){
    ClassPathResource resource = new ClassPathResource("spring.cfg.xml");
    BeanFactory factory = new XmlBeanFactory(resource);
    System.out.println(factory.getBean("myBean"));
  }
 
}
 


qrtt1 edited on 2007-05-16 22:23
reply to postreply to post
蝸牛角上爭何事?石火光中寄此身,隨富隨貧且歡樂,不開口笑是癡人。
my notes
» JWorld@TW »  Java Application Framework » Spring

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8