1. 程式人生 > >spring ref &history&design philosophy

spring ref &history&design philosophy

socket spa tps vid ssi pre http too pan

在bean的內部引用另一個bean對象:

  使用ref標簽對其進行引用: <ref bean="viewResolver2"/>

技術分享圖片
<bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/" />
        <property name="suffix" value=".jsp" />
        <property name="order" value="2"/>
</bean>
技術分享圖片 技術分享圖片
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="viewResolvers">
        <list>
            <bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"/>   
            <!-- 引用外部id為viewResolver的bean -->
            <ref bean="viewResolver"/>
        </list>
    </property> 
</bean>
技術分享圖片

  

ref屬性:用來給一個對象的屬性設置值

技術分享圖片
使用<ref bean="viewResolver"/>
bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!-- 在spring框架加載時創建 -->
 <bean id="borrowDao" class="dao.impl.BorrowDao" primary="true"  lazy-init="true">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
技術分享圖片

  

ref標簽:用來引用另一個bean:

<ref bean="viewResolver"/>,在spring容器中群釗id為viewResolver的bean對象

History

Spring最早在2003年,由於J2EE過於復雜而被開發出來的。有人認為Spring和Java EE是競爭關系,但Spring更像是對Java EE的補充。Spring整合了一些EE的標準:

  • Servlet API
  • WebSocket API
  • Concurrency Utilities(並發性)
  • JSON Binding API 簡介
  • Bean Validation(數據校驗) 簡介
  • JPA
  • JMS
  • Dependency Injection and Common Annotations

Java EE在app開發中的角色在隨時間變化。早期的時候,javaEE和Spring開發的應用是部署在application server上的,今天,在Spring Boot的幫助下開發變得友好且更加雲端化(devops and cloud-friendly),嵌入Servelet容器,非常容易改變。在Spring Framework5中,一個webflux應用甚至不需要Servlet API並可以運行在不含Servlet容器的server上。

Spring projects目前在逐漸豐富,建立在Spring Framework上的projects有Spring Boot,Spring Security,Spring Data,Spring Cloud,Spring Batch…

Spring的design philosophy

  • Provide choice at every level 盡可能允許不改動code的情況下變更design
  • Accommodate diverse perspectives 允許設計的靈活性
  • Maintain strong backward compatibility 對JDK和第三方庫的高兼容性
  • Care about API design API被設計地簡單易用
  • Set high standards for code quality 註意代碼的整潔

spring ref &history&design philosophy