一. Aspect就是把会在应用中的不同地方重复出现的非业务功能的模块化,比如日志.事务.安全.缓存 In software development, functions that span multiple points of an application arecalled cross-cutting concerns. Typically, these cross-cutting concerns are conceptuallyseparate from (but often embed…
一. 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…
一. 不同的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…
一. 假设有如下情况,有一个演凑者和一批观众,要实现在演凑者的演凑方法前织入观众的"坐下"."关手机方法",在演凑结束后,如果成功,则织入观众"鼓掌",演凑出错则观众要求"回水" 基本的类如下: 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)不限返回类型,不限…
一. 1.Advice Advice是切面的要做的操作,它定义了what.when(什么时候要做什么事) aspects have a purpose—a job they’re meant to do. In AOP terms, the jobof an aspect is called advice.Advice defines both the what and the when of an aspect. In addition to describingthe job that an…
1.AOP是面向对象编程的有力补充,它可以让你把分散在应用中的公共辅助功能抽取成模块,以灵活配置,减少了重复代码,让类更关注于自身的功能…
一. 1. package concert; public interface CriticismEngine { public String getCriticism(); } 2. package concert; public class CriticismEngineImpl implements CriticismEngine { public CriticismEngineImpl() {} // injected private String[] criticismPool; pu…
一. 1.配置文件为xml时则切面类不用写aop的anotation package com.springinaction.springidol; public class Magician implements MindReader { private String thoughts; public void interceptThoughts(String thoughts) { System.out.println("Intercepting volunteer's thoughts&qu…
一. 情景:有个魔术师会读心术,常人一想一事物他就能读到.以魔术师为切面织入常人的内心. 二. 1. // <start id="mindreader_java" /> package com.springinaction.springidol; public interface MindReader { void interceptThoughts(String thoughts); String getThoughts(); } // <end id="…
一. 假设有情形如:cd里有很多轨,当播放音乐时,要统计每个音轨的播放次数,这些统计操作不应放在播放方法里,因为统计不是播放音乐的主要职责,这种情况适合应用AOP. 二. 1. package soundsystem; public interface CompactDisc { void play(); void playTrack(int trackNumber); } 2. package soundsystem; import java.util.List; public class B…
一.注解@AspectJ形式 1. package com.springinaction.springidol; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; @Aspect public cl…
一. you can also define pointcuts that can be used across multiple aspects by placing the <aop:pointcut> elements within the scope of the <aop:config> element. 1.其他类和上个例子一样,观众类比使用@AspectJ方式的少了@AspectJ标签及pointcut,before.after等定义 package com.spri…
一.结构 二.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…
一.用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…
一. 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…
一.什么是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…