org.springframework.instrument.classloading.LoadTimeWeaver Java Examples

The following examples show how to use org.springframework.instrument.classloading.LoadTimeWeaver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultContextLoadTimeWeaver.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) {
	String name = classLoader.getClass().getName();
	try {
		if (name.startsWith("weblogic")) {
			return new WebLogicLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.glassfish")) {
			return new GlassFishLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.apache.catalina")) {
			return new TomcatLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.jboss")) {
			return new JBossLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("com.ibm")) {
			return new WebSphereLoadTimeWeaver(classLoader);
		}
	}
	catch (IllegalStateException ex) {
		logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage());
	}
	return null;
}
 
Example #2
Source File: DefaultContextLoadTimeWeaver.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
	LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
	if (serverSpecificLoadTimeWeaver != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Determined server-specific load-time weaver: " +
					serverSpecificLoadTimeWeaver.getClass().getName());
		}
		this.loadTimeWeaver = serverSpecificLoadTimeWeaver;
	}
	else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		logger.info("Found Spring's JVM agent for instrumentation");
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(classLoader);
	}
	else {
		try {
			this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
			logger.info("Using a reflective load-time weaver for class loader: " +
					this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
		}
		catch (IllegalStateException ex) {
			throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
					"Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar");
		}
	}
}
 
Example #3
Source File: DefaultContextLoadTimeWeaver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) {
	String name = classLoader.getClass().getName();
	try {
		if (name.startsWith("weblogic")) {
			return new WebLogicLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.glassfish")) {
			return new GlassFishLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.apache.catalina")) {
			return new TomcatLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.jboss")) {
			return new JBossLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("com.ibm")) {
			return new WebSphereLoadTimeWeaver(classLoader);
		}
	}
	catch (IllegalStateException ex) {
		logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage());
	}
	return null;
}
 
Example #4
Source File: DefaultContextLoadTimeWeaver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
	LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
	if (serverSpecificLoadTimeWeaver != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Determined server-specific load-time weaver: " +
					serverSpecificLoadTimeWeaver.getClass().getName());
		}
		this.loadTimeWeaver = serverSpecificLoadTimeWeaver;
	}
	else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		logger.info("Found Spring's JVM agent for instrumentation");
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(classLoader);
	}
	else {
		try {
			this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
			logger.info("Using a reflective load-time weaver for class loader: " +
					this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
		}
		catch (IllegalStateException ex) {
			throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
					"Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar");
		}
	}
}
 
Example #5
Source File: LoadTimeWeaverAwareProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof LoadTimeWeaverAware) {
		LoadTimeWeaver ltw = this.loadTimeWeaver;
		if (ltw == null) {
			Assert.state(this.beanFactory != null,
					"BeanFactory required if no LoadTimeWeaver explicitly specified");
			ltw = this.beanFactory.getBean(
					ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME, LoadTimeWeaver.class);
		}
		((LoadTimeWeaverAware) bean).setLoadTimeWeaver(ltw);
	}
	return bean;
}
 
Example #6
Source File: EnableLoadTimeWeavingTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingEnabled() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingEnabled.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	verify(loadTimeWeaver).addTransformer(isA(ClassFileTransformer.class));
}
 
Example #7
Source File: EnableLoadTimeWeavingTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingDisabled() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingDisabled.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	verifyZeroInteractions(loadTimeWeaver);
}
 
Example #8
Source File: EnableLoadTimeWeavingTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingAutodetect() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingAutodetect.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	// no expectations -> a class file transformer should NOT be added
	// because no META-INF/aop.xml is present on the classpath
	verifyZeroInteractions(loadTimeWeaver);
}
 
Example #9
Source File: DefaultContextLoadTimeWeaver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Nullable
protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) {
	String name = classLoader.getClass().getName();
	try {
		if (name.startsWith("org.apache.catalina")) {
			return new TomcatLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.glassfish")) {
			return new GlassFishLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.jboss.modules")) {
			return new JBossLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("com.ibm.ws.classloader")) {
			return new WebSphereLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("weblogic")) {
			return new WebLogicLoadTimeWeaver(classLoader);
		}
	}
	catch (Exception ex) {
		if (logger.isInfoEnabled()) {
			logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage());
		}
	}
	return null;
}
 
Example #10
Source File: DefaultContextLoadTimeWeaver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
	LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
	if (serverSpecificLoadTimeWeaver != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Determined server-specific load-time weaver: " +
					serverSpecificLoadTimeWeaver.getClass().getName());
		}
		this.loadTimeWeaver = serverSpecificLoadTimeWeaver;
	}
	else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		logger.debug("Found Spring's JVM agent for instrumentation");
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(classLoader);
	}
	else {
		try {
			this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
			if (logger.isDebugEnabled()) {
				logger.debug("Using reflective load-time weaver for class loader: " +
						this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
			}
		}
		catch (IllegalStateException ex) {
			throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
					"Java virtual machine with Spring's agent: -javaagent:spring-instrument-{version}.jar");
		}
	}
}
 
Example #11
Source File: EnableLoadTimeWeavingTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingDisabled() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingDisabled.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	verifyZeroInteractions(loadTimeWeaver);
}
 
Example #12
Source File: DefaultContextLoadTimeWeaver.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
	LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
	if (serverSpecificLoadTimeWeaver != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Determined server-specific load-time weaver: " +
					serverSpecificLoadTimeWeaver.getClass().getName());
		}
		this.loadTimeWeaver = serverSpecificLoadTimeWeaver;
	}
	else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		logger.debug("Found Spring's JVM agent for instrumentation");
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(classLoader);
	}
	else {
		try {
			this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
			if (logger.isDebugEnabled()) {
				logger.debug("Using reflective load-time weaver for class loader: " +
						this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
			}
		}
		catch (IllegalStateException ex) {
			throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
					"Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar");
		}
	}
}
 
Example #13
Source File: DefaultContextLoadTimeWeaver.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Nullable
protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) {
	String name = classLoader.getClass().getName();
	try {
		if (name.startsWith("org.apache.catalina")) {
			return new TomcatLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.glassfish")) {
			return new GlassFishLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.jboss.modules")) {
			return new JBossLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("com.ibm.ws.classloader")) {
			return new WebSphereLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("weblogic")) {
			return new WebLogicLoadTimeWeaver(classLoader);
		}
	}
	catch (Exception ex) {
		if (logger.isInfoEnabled()) {
			logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage());
		}
	}
	return null;
}
 
Example #14
Source File: LoadTimeWeaverAwareProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof LoadTimeWeaverAware) {
		LoadTimeWeaver ltw = this.loadTimeWeaver;
		if (ltw == null) {
			Assert.state(this.beanFactory != null,
					"BeanFactory required if no LoadTimeWeaver explicitly specified");
			ltw = this.beanFactory.getBean(
					ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME, LoadTimeWeaver.class);
		}
		((LoadTimeWeaverAware) bean).setLoadTimeWeaver(ltw);
	}
	return bean;
}
 
Example #15
Source File: EnableLoadTimeWeavingTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingAutodetect() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingAutodetect.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	// no expectations -> a class file transformer should NOT be added
	// because no META-INF/aop.xml is present on the classpath
	verifyZeroInteractions(loadTimeWeaver);
}
 
Example #16
Source File: EnableLoadTimeWeavingTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingEnabled() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingEnabled.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	verify(loadTimeWeaver).addTransformer(isA(ClassFileTransformer.class));
}
 
Example #17
Source File: EnableLoadTimeWeavingTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingEnabled() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingEnabled.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	verify(loadTimeWeaver).addTransformer(isA(ClassFileTransformer.class));
}
 
Example #18
Source File: EnableLoadTimeWeavingTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingAutodetect() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingAutodetect.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	// no expectations -> a class file transformer should NOT be added
	// because no META-INF/aop.xml is present on the classpath
	verifyZeroInteractions(loadTimeWeaver);
}
 
Example #19
Source File: LoadTimeWeaverAwareProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof LoadTimeWeaverAware) {
		LoadTimeWeaver ltw = this.loadTimeWeaver;
		if (ltw == null) {
			Assert.state(this.beanFactory != null,
					"BeanFactory required if no LoadTimeWeaver explicitly specified");
			ltw = this.beanFactory.getBean(
					ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME, LoadTimeWeaver.class);
		}
		((LoadTimeWeaverAware) bean).setLoadTimeWeaver(ltw);
	}
	return bean;
}
 
Example #20
Source File: EnableLoadTimeWeavingTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingDisabled() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingDisabled.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	verifyZeroInteractions(loadTimeWeaver);
}
 
Example #21
Source File: LoadTimeWeaverAwareProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof LoadTimeWeaverAware) {
		LoadTimeWeaver ltw = this.loadTimeWeaver;
		if (ltw == null) {
			Assert.state(this.beanFactory != null,
					"BeanFactory required if no LoadTimeWeaver explicitly specified");
			ltw = this.beanFactory.getBean(
					ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME, LoadTimeWeaver.class);
		}
		((LoadTimeWeaverAware) bean).setLoadTimeWeaver(ltw);
	}
	return bean;
}
 
Example #22
Source File: SpringPersistenceUnitInfo.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize this PersistenceUnitInfo with the LoadTimeWeaver SPI interface
 * used by Spring to add instrumentation to the current class loader.
 */
public void init(LoadTimeWeaver loadTimeWeaver) {
	Assert.notNull(loadTimeWeaver, "LoadTimeWeaver must not be null");
	this.loadTimeWeaver = loadTimeWeaver;
	this.classLoader = loadTimeWeaver.getInstrumentableClassLoader();
}
 
Example #23
Source File: EntityManagerFactoryServiceImpl.java    From multitenant with Apache License 2.0 4 votes vote down vote up
@Override
public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver) {
	this.loadTimeWeaver = loadTimeWeaver;
}
 
Example #24
Source File: AspectJWeavingEnabler.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver) {
	this.loadTimeWeaver = loadTimeWeaver;
}
 
Example #25
Source File: KradEntityManagerFactoryBean.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver) {
    persistenceUnitManager.setLoadTimeWeaver(loadTimeWeaver);
}
 
Example #26
Source File: EnableLoadTimeWeavingTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void control() {
	GenericXmlApplicationContext ctx =
		new GenericXmlApplicationContext(getClass(), "EnableLoadTimeWeavingTests-context.xml");
	ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
}
 
Example #27
Source File: EnableLoadTimeWeavingTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public LoadTimeWeaver getLoadTimeWeaver() {
	return mock(LoadTimeWeaver.class);
}
 
Example #28
Source File: ChaosMonkeyLoadTimeWeaving.java    From chaos-monkey-spring-boot with Apache License 2.0 4 votes vote down vote up
@Override
public LoadTimeWeaver loadTimeWeaver() {
  return new ReflectiveLoadTimeWeaver();
}
 
Example #29
Source File: EnableLoadTimeWeavingTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public LoadTimeWeaver getLoadTimeWeaver() {
	return mock(LoadTimeWeaver.class);
}
 
Example #30
Source File: RefreshAutoConfiguration.java    From spring-cloud-commons with Apache License 2.0 4 votes vote down vote up
@Override
public void setLoadTimeWeaver(LoadTimeWeaver ltw) {
}