Browse Source

Polishing

pull/770/head
Juergen Hoeller 11 years ago
parent
commit
595cdf05e9
  1. 5
      spring-aspects/src/test/java/org/springframework/transaction/aspectj/JtaTransactionAspectsTests.java
  2. 8
      spring-beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java
  3. 14
      spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java
  4. 5
      spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java
  5. 23
      spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java

5
spring-aspects/src/test/java/org/springframework/transaction/aspectj/JtaTransactionAspectsTests.java

@ -17,7 +17,6 @@
package org.springframework.transaction.aspectj; package org.springframework.transaction.aspectj;
import java.io.IOException; import java.io.IOException;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import org.junit.Before; import org.junit.Before;
@ -132,6 +131,7 @@ public class JtaTransactionAspectsTests {
} }
protected static class JtaAnnotationProtectedAnnotatedMember { protected static class JtaAnnotationProtectedAnnotatedMember {
public void doSomething() { public void doSomething() {
@ -143,6 +143,7 @@ public class JtaTransactionAspectsTests {
} }
} }
protected static class JtaAnnotationPrivateAnnotatedMember { protected static class JtaAnnotationPrivateAnnotatedMember {
public void doSomething() { public void doSomething() {
@ -154,6 +155,7 @@ public class JtaTransactionAspectsTests {
} }
} }
@Configuration @Configuration
protected static class Config { protected static class Config {
@ -168,7 +170,6 @@ public class JtaTransactionAspectsTests {
aspect.setTransactionManager(transactionManager()); aspect.setTransactionManager(transactionManager());
return aspect; return aspect;
} }
} }
} }

8
spring-beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java

@ -22,6 +22,7 @@ import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.UndeclaredThrowableException;
import java.security.AccessControlContext; import java.security.AccessControlContext;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
@ -1179,7 +1180,12 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
throw new TypeMismatchException(propertyChangeEvent, pd.getPropertyType(), ex.getTargetException()); throw new TypeMismatchException(propertyChangeEvent, pd.getPropertyType(), ex.getTargetException());
} }
else { else {
throw new MethodInvocationException(propertyChangeEvent, ex.getTargetException()); Throwable cause = ex.getTargetException();
if (cause instanceof UndeclaredThrowableException) {
// May happen e.g. with Groovy-generated methods
cause = cause.getCause();
}
throw new MethodInvocationException(propertyChangeEvent, cause);
} }
} }
catch (Exception ex) { catch (Exception ex) {

14
spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java vendored

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -162,13 +162,12 @@ public @interface EnableCaching {
* Indicate whether subclass-based (CGLIB) proxies are to be created as opposed * Indicate whether subclass-based (CGLIB) proxies are to be created as opposed
* to standard Java interface-based proxies. The default is {@code false}. <strong> * to standard Java interface-based proxies. The default is {@code false}. <strong>
* Applicable only if {@link #mode()} is set to {@link AdviceMode#PROXY}</strong>. * Applicable only if {@link #mode()} is set to {@link AdviceMode#PROXY}</strong>.
*
* <p>Note that setting this attribute to {@code true} will affect <em>all</em> * <p>Note that setting this attribute to {@code true} will affect <em>all</em>
* Spring-managed beans requiring proxying, not just those marked with * Spring-managed beans requiring proxying, not just those marked with {@code @Cacheable}.
* {@code @Cacheable}. For example, other beans marked with Spring's * For example, other beans marked with Spring's {@code @Transactional} annotation will
* {@code @Transactional} annotation will be upgraded to subclass proxying at the same * be upgraded to subclass proxying at the same time. This approach has no negative
* time. This approach has no negative impact in practice unless one is explicitly * impact in practice unless one is explicitly expecting one type of proxy vs another,
* expecting one type of proxy vs another, e.g. in tests. * e.g. in tests.
*/ */
boolean proxyTargetClass() default false; boolean proxyTargetClass() default false;
@ -185,4 +184,5 @@ public @interface EnableCaching {
* The default is {@link Ordered#LOWEST_PRECEDENCE}. * The default is {@link Ordered#LOWEST_PRECEDENCE}.
*/ */
int order() default Ordered.LOWEST_PRECEDENCE; int order() default Ordered.LOWEST_PRECEDENCE;
} }

5
spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,7 +24,6 @@ import groovy.lang.MetaClass;
import groovy.lang.Script; import groovy.lang.Script;
import org.codehaus.groovy.control.CompilationFailedException; import org.codehaus.groovy.control.CompilationFailedException;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanFactoryAware;
@ -102,7 +101,7 @@ public class GroovyScriptFactory implements ScriptFactory, BeanFactoryAware, Bea
@Override @Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { public void setBeanFactory(BeanFactory beanFactory) {
if (beanFactory instanceof ConfigurableListableBeanFactory) { if (beanFactory instanceof ConfigurableListableBeanFactory) {
((ConfigurableListableBeanFactory) beanFactory).ignoreDependencyType(MetaClass.class); ((ConfigurableListableBeanFactory) beanFactory).ignoreDependencyType(MetaClass.class);
} }

23
spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -94,7 +94,7 @@ import org.springframework.util.StringUtils;
* &lt;property name="message" value="Hello World!"/&gt; * &lt;property name="message" value="Hello World!"/&gt;
* &lt;/bean&gt; * &lt;/bean&gt;
* *
* &lt;bean id="groovyMessenger" class="org.springframework.scripting.bsh.GroovyScriptFactory"&gt; * &lt;bean id="groovyMessenger" class="org.springframework.scripting.groovy.GroovyScriptFactory"&gt;
* &lt;constructor-arg value="classpath:mypackage/Messenger.groovy"/&gt; * &lt;constructor-arg value="classpath:mypackage/Messenger.groovy"/&gt;
* &lt;property name="message" value="Hello World!"/&gt; * &lt;property name="message" value="Hello World!"/&gt;
* &lt;/bean&gt;</pre> * &lt;/bean&gt;</pre>
@ -346,17 +346,16 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
* @param scriptedObjectBeanName the name of the internal scripted object bean * @param scriptedObjectBeanName the name of the internal scripted object bean
*/ */
protected void prepareScriptBeans(BeanDefinition bd, String scriptFactoryBeanName, String scriptedObjectBeanName) { protected void prepareScriptBeans(BeanDefinition bd, String scriptFactoryBeanName, String scriptedObjectBeanName) {
// Avoid recreation of the script bean definition in case of a prototype. // Avoid recreation of the script bean definition in case of a prototype.
synchronized (this.scriptBeanFactory) { synchronized (this.scriptBeanFactory) {
if (!this.scriptBeanFactory.containsBeanDefinition(scriptedObjectBeanName)) { if (!this.scriptBeanFactory.containsBeanDefinition(scriptedObjectBeanName)) {
this.scriptBeanFactory.registerBeanDefinition(scriptFactoryBeanName, this.scriptBeanFactory.registerBeanDefinition(
createScriptFactoryBeanDefinition(bd)); scriptFactoryBeanName, createScriptFactoryBeanDefinition(bd));
ScriptFactory scriptFactory = this.scriptBeanFactory ScriptFactory scriptFactory =
.getBean(scriptFactoryBeanName, ScriptFactory.class); this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, ScriptSource scriptSource =
scriptFactory.getScriptSourceLocator()); getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
Class<?>[] interfaces = scriptFactory.getScriptInterfaces(); Class<?>[] interfaces = scriptFactory.getScriptInterfaces();
Class<?>[] scriptedInterfaces = interfaces; Class<?>[] scriptedInterfaces = interfaces;
@ -365,8 +364,8 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
scriptedInterfaces = ObjectUtils.addObjectToArray(interfaces, configInterface); scriptedInterfaces = ObjectUtils.addObjectToArray(interfaces, configInterface);
} }
BeanDefinition objectBd = createScriptedObjectBeanDefinition(bd, scriptFactoryBeanName, scriptSource, BeanDefinition objectBd = createScriptedObjectBeanDefinition(
scriptedInterfaces); bd, scriptFactoryBeanName, scriptSource, scriptedInterfaces);
long refreshCheckDelay = resolveRefreshCheckDelay(bd); long refreshCheckDelay = resolveRefreshCheckDelay(bd);
if (refreshCheckDelay >= 0) { if (refreshCheckDelay >= 0) {
objectBd.setScope(BeanDefinition.SCOPE_PROTOTYPE); objectBd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
@ -569,7 +568,7 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
proxyFactory.setInterfaces(interfaces); proxyFactory.setInterfaces(interfaces);
if (proxyTargetClass) { if (proxyTargetClass) {
classLoader = null; // force use of Class.getClassLoader() classLoader = null; // force use of Class.getClassLoader()
proxyFactory.setProxyTargetClass(proxyTargetClass); proxyFactory.setProxyTargetClass(true);
} }
DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts); DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);

Loading…
Cancel
Save