ClassLoaderProxyService implements DefiningClassService { @Override public ClassLoader getProxyClassLoader(final Class<?> forClass) { return loader; } ClassLoaderProxyService(final WebBeansContext context); protected  ClassLoaderProxyService(final ProxiesClassLoader loader); @Override ClassLoader getProxyClassLoader(final Class<?> forClass); @Override Class<T> defineAndLoad(final String name, final byte[] bytecode, final Class<T> proxiedClass);  }
@Test public void defineInProxy() throws NoSuchMethodException { final Properties config = new Properties(); config.setProperty(DefiningClassService.class.getName(), ClassLoaderProxyService.class.getName()); final WebBeansContext context = new WebBeansContext(emptyMap(), config); final NormalScopeProxyFactory factory = new NormalScopeProxyFactory(context); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); final Class<MyBean> proxyClass = factory.createProxyClass(contextClassLoader, MyBean.class); assertNotEquals(contextClassLoader, proxyClass.getClassLoader()); final ClassLoader proxyLoader = context.getService(DefiningClassService.class).getProxyClassLoader(proxyClass); assertEquals(proxyLoader, proxyClass.getClassLoader()); proxyClass.getMethod("ok", String.class); }