一. 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…
一. 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.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…
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…
一. 1.Spring MVC provides several ways that a client can pass data into a controller’s handler method. These include  Query parameters Form parameters Path variables 二.以query parameters的形式给action传参数 1.传参数 @Test public void shouldShowPagedSpittles()…
一.JpaRepository 1.要使Spring自动生成实现类的步骤 (1)配置文件xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:…
一.注入EntityManagerFactory的方式 package com.habuma.spittr.persistence; import java.util.List; import javax.persistence.EntityManagerFactory; import javax.persistence.PersistenceUnit; import org.springframework.dao.DataAccessException; import org.springfr…
一.EntityManagerFactory的种类 1.The JPA specification defines two kinds of entity managers:  Application-managed—Entity managers are created when an application directly requests one from an entity manager factory. With application-managed entity manage…
一.结构 二.Repository层 1. package spittr.db; import java.util.List; import spittr.domain.Spitter; /** * Repository interface with operations for {@link Spitter} persistence. * @author habuma */ public interface SpitterRepository { long count(); Spitter s…
No matter what happens, good or bad, the outcome of a servlet request is a servlet response. If an exception occurs during request processing, the outcome is still a servlet response. Somehow, the exception must be translated into a response. Spring…
一.什么是multipart The Spittr application calls for file uploads in two places. When a new user registers with the application, you’d like them to be able to provide a picture to associate with their profile. And when a user posts a new Spittle , they ma…
一.所有声明都用xml 1. <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=&quo…
一.在Spring中使用thymeleaf的步骤 1.配置 In order to use Thymeleaf with Spring, you’ll need to configure three beans that enable Thymeleaf-Spring integration: A ThymeleafViewResolver that resolves Thymeleaf template views from logical view names A SpringTempl…
一. SPRING支持的GENERAL TAG LIBRARY 1. 二.用<s:message>和ReloadableResourceBundleMessageSource实现国际化 1.配置ReloadableResourceBundleMessageSource,它能it has the ability to reload message properties without recompiling or restarting the application. package spitt…
一. Spring offers two JSP tag libraries to help define the view of your Spring MVC web views. One tag library renders HTML form tags that are bound to a model attribute. The other has a hodgepodge of utility tags that come in handy from time to time.…
一.Spring支持的View Resolver 二.InternalResourceViewResolver Spring supports JSP views in two ways: InternalResourceViewResolver  Spring provides two JSP tag libraries, one for form-to-model binding and one providing general utility features. 1.在java中定义…
一. Starting with Spring 3.0, Spring supports the Java Validation API in Spring MVC . No extra configuration is required to make Java Validation work in Spring MVC . You just need to make sure an implementation of the Java API , such as Hibernate Vali…
一 1.以path parameters的形式给action传参数 @Test public void testSpittle() throws Exception { Spittle expectedSpittle = new Spittle("Hello", new Date()); SpittleRepository mockRepository = mock(SpittleRepository.class); when(mockRepository.findOne(12345)…
一.RequestMapping 1.可以写在方法上或类上,且值可以是数组 package spittr.web; import static org.springframework.web.bind.annotation.RequestMethod.*; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bin…
一. 二.用Java文件配置web application 1. package spittr.config; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; import spittr.web.WebConfig; public class SpitterWebInitializer extends AbstractAnnotationCon…
一. 1.Introduction的作用是给类动态的增加方法 When Spring discovers a bean annotated with @Aspect , it will automatically create a proxy that delegates calls to either the proxied bean or to the introduction implementation, depending on whether the method called be…
一. 假设有如下情况,有一个演凑者和一批观众,要实现在演凑者的演凑方法前织入观众的"坐下"."关手机方法",在演凑结束后,如果成功,则织入观众"鼓掌",演凑出错则观众要求"回水" 基本的类如下: 1. package com.springinaction.springidol; public interface Instrument { public void play(); } 2. package com.springin…
一. 1.在Spring中,pointcut是通过AspectJ’s pointcut expression language来定义的,但spring只支持它的一部分,如果超出范围就会报IllegalArgumentException,支持的语法如下: 其实就是支持execution(),然后通过其他的标签来缩小范围 2.例子 package concert; public interface Performance { public void perform(); } (1)不限返回类型,不限…
一. 不同的Aop框架在支持aspect何时.如何织入到目标中是不一样的.如AspectJ和Jboss支持在构造函数和field被修改时织入,但spring不支持,spring只支持一般method的织入.spring通过以下四种方式支持AOP:  Classic Spring proxy-based AOP Pure- POJO aspects @AspectJ annotation-driven aspects Injected AspectJ aspects (available…