I am trying to get to the real classes of an instance that I injected via CDI. I only get a designation as a class name, which is composed of the name of the interface, a sequence of numbers and the character string "$Proxy$_$$_Weld$EnterpriseProxy$".
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface TestProvider {
String value();
}
public interface TestConnector {
}
@TestProvider("TestConnector1")
@Stateless
public class Test1 implements TestConnector {
}
@Default
@TestProvider("TestConnector2")
@Stateless
public class Test12 implements TestConnector {
}
@Stateless
public class TestFactory {
@Inject
@Any
private Instance<TestConnector> testConnectors;
public TestConnector getConnector(String name) {
...
}
public Set<String> listAllTestConnectorNames(){
try {
Set<String> connectors = new HashSet<String>();
this.testConnectors.forEach(con -> {
System.out.println(con.getClass().getName());
for(Annotation x : con.getClass().getAnnotations()) {
if(x instanceof TestProvider) {
String name = ((TestProvider) x).value();
System.out.println(name);
connectors.add(name);
}
}
this.testConnectors.destroy(con);
});
return connectors;
} catch(Exception e) {
...
}
}
The function listAllTestConnectorNames should go through all the determined instances and return the value of the annotation TestProvider as a list. I would expect the following list.
- TestConnector1
- TestConnector2
But the instances that I received are of the type de.test.con1.TestConnector $ 710153185 $ Proxy $ _ $$ _ Weld $ EnterpriseProxy $ or de.test.con2.TestConnector $ 219965632 $ Proxy $ _ $$ _ Weld $ EnterpriseProxy $
How can I read out the values I am looking for?