2

I've been trying to inject a hashmap into a class. According to this post: Auto-wiring a List using util schema gives NoSuchBeanDefinitionException I should be using @Resource rather than @Autowire for a map.

My code looks like this:

@Configurable
public class MyClass
{   

    @Resource(name="myMap")
    private Map<String,String> myMap = new HashMap<String, String>();

My config looks like this:

<context:annotation-config/>
<context:component-scan base-package="com.MyClass"/>

<util:map id="myMap" 
            key-type="java.lang.String"
            value-type="java.lang.String">
    <entry key="k1" value="v1"/>
    <entry key="k2" value="v2"/>
</util:map>

The application starts up OK, but when I try to run code that references MyClass, I get this WebSphere error:

CNTR0035E: EJB container caught com.ibm.wsspi.injectionengine.InjectionException: Failed to process bindings for metadata
    at com.ibm.ws.injectionengine.InjectionEngineImpl.processBindings(InjectionEngineImpl.java:529)
    at com.ibm.ws.injectionengine.InjectionEngineImpl.processInjectionMetaData(InjectionEngineImpl.java:322)
    at com.ibm.ws.util.ComponentNameSpaceHelper.populateJavaNameSpace(ComponentNameSpaceHelper.java:806)
...
Caused by: com.ibm.wsspi.injectionengine.InjectionException: CWNEN0044E: A resource reference binding could not be found for the following resource references [myMap], defined for the MyService component.
    at com.ibm.wsspi.injectionengine.InjectionProcessor.collectInjectionNBindingData(InjectionProcessor.java:1042)
    at com.ibm.ws.injectionengine.InjectionEngineImpl.processBindings(InjectionEngineImpl.java:516)
    ... 52 more
 and is throwing com.ibm.ejs.container.ContainerException: Failed to initialize BeanMetaData instance; nested exception is: 
    com.ibm.wsspi.injectionengine.InjectionException: Failed to process bindings for metadata.

Is there any way to inject the map into my class in WebSphere?

(using Spring 2.5, WebSphere 7)


Earlier, I'd tried autowiring by name with this code:

@Configurable(autowire=Autowire.BY_NAME, preConstruction=true)
public class MyClass
{   

@Qualifier("myMap")
@Autowired(required=true)
    private Map<String,String> myMap = new HashMap<String, String>();

and with this config:

<context:annotation-config/>
<context:component-scan base-package="com.MyClass"/>

<util:map id="myMap" 
            key-type="java.lang.String"
            value-type="java.lang.String">
    <entry key="k1" value="v1"/>
    <entry key="k2" value="v2"/>
</util:map>

And the result is that the fields I'm trying to autowire are null.

Community
  • 1
  • 1
FrustratedWithFormsDesigner
  • 26,726
  • 31
  • 139
  • 202
  • I have the same problem with an application that was working on the very same WAS after moving from RSA to Eclipse Neon with WAS8.5 plugin. Am clueless so far. It does work for colleagues with identical config, though. – JRA_TLL Jul 28 '17 at 15:41

2 Answers2

0

It seems autowire byType or byName works.. have you tried..??

saagaravk
  • 93
  • 1
  • 2
  • 11
0

I was able to get my application to deploy again by adding

Ignore-Scanning-Packages: foo.myapp

(replace foo.myapp by your base package ;) )

However, this feels rather like a workaround. On the other hand, this reduces app startup time slightly.

JRA_TLL
  • 1,186
  • 12
  • 23