一. DataSource在应用和开发环境的产生方式不同,可以用srping 的profile管理 Spring’s solution for environment-specific beans isn’t much different from build-timesolutions. Certainly, an environment-specific decision is made as to which beans willand won’t be created. But rath…
一. 1.SpEL expressions are framed with  #{ ... } 2.SpEl的作用 Sp EL has a lot of tricks up its sleeves, including the following: The ability to reference beans by their ID s Invoking methods and accessing properties on objects Mathematical, relational…
一.用placeholder给bean运行时注入值的步骤 Spring取得placeholder的值是用${...} 1.声明placeholder bean (1)java方式 In order to use placeholder values, you must configure either a PropertyPlaceholder-Configurer bean or a PropertySourcesPlaceholderConfigurer bean. Starting wit…
一. 直观的给bean注入值如下: @Bean public CompactDisc sgtPeppers() { return new BlankDisc( "Sgt. Pepper's Lonely Hearts Club Band", "The Beatles"); } < bean id = "sgtPeppers" class = "soundsystem.BlankDisc" c: _title = &quo…
一. Spring的bean默认是单例的 But sometimes you may find yourself working with a mutable class that does main-tain some state and therefore isn’t safe for reuse. In that case, declaring the class as asingleton bean probably isn’t a good idea because that obje…
一. 假设有如下三个类实现同一个接口,则自动装配时会产生歧义 @Component public class Cake implements Dessert { ... } @Component public class Cookies implements Dessert { ... } @Component public class IceCream implements Dessert { ... } @Autowired public void setDessert(Dessert de…
一. Spring honors two separate properties when determining which profiles are active:spring.profiles.active and spring.profiles.default . If spring.profiles.activeis set, then its value determines which profiles are active. But if spring.profiles.acti…
1.When injecting properties and constructor arguments on beans that are created via component-scanning, you can use the @Value annotation, much as you saw earlierwith property placeholders. Rather than use a placeholder expression, however, youuse a…
一. The @Qualifier annotation is the main way to work with qualifiers. It can beapplied alongside @Autowired or @Inject at the point of injection to specify whichbean you want to be injected. For example, let’s say you want to ensure that theIceCream…
一.用@Conditional根据条件决定是否要注入bean 1. package com.habuma.restfun; public class MagicBean { } 2. package com.habuma.restfun; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springfr…