Reputation: 579
We have a Spring 3.1 MVC app packaged as a WAR, deployed on GlassFish 3 application server. The application was once Spring 2, XML-based, and after migration to Spring 3 we slowly refactored it to an annotation-based IoC configuration.
One of the core parts of the application is a custom bean factory, which performs plain JNDI lookups for remote EJBs. However, the parameters of the lookup are stored in an external properties file, which can be changed during runtime - hence the need for a custom factory. We haven't found a way to configure beans produced by the factory through annotations, so the configuration is still in XML like that:
<bean id="exampleEjb" factory-method="lookup"
class="com.example.EjbServiceLocator" lazy-init="false" scope="session">
<constructor-arg value="example.ejb.connstr" /> <!-- remote hosts: x.y.z.1:3701,x.y.z.2:3701 - cluster here! -->
<constructor-arg value="example.ejb.name" /> <!-- JNDI name: ejb/example/remoteService -->
<constructor-arg value="com.example.service.RemoteInterface" /> <!-- this is interface exposed by remote bean -->
<constructor-arg ref="configReader" /> <!-- custom bean monitoring configuration changes -->
</bean>
Using a factory here means that the bean class as seen by the container is com.example.EjbServiceLocator
instead of com.example.service.RemoteInterface
. Autowire-by-type gets confused and the @Autowire
annotation cannot match the expected type with the bean name provided by @Qualifier
. So we have to use @Resource(name="exampleEjb")
.
Well, it works. With one "but". Every time the application is (re-)deployed, the application sever scans the archive and tries to manage the @Resource
annotation by itself. And it fails, leaving ugly SEVERE messages in the log, causing an increased heart rate in our support department.
What can I do here, to either:
@Resource
annotations to something not recognized by the Java EE container?Upvotes: 1
Views: 642
Reputation: 49915
For Point 1:
You can try adding a metadata-complete="true"
attribute to the webapp
element in your web.xml file, this should prevent scanning and resolution of @Resource
annotations by the container.
For Point 2, 3:
Implementing a Spring Factory Bean may be a better option, this way you can specify the exact type to expect using the getObjectType()
api.
Upvotes: 1