NoUniqueBeanDefinitionException while wiring up InternalResourceViewResolver - spring

I'm currently trying to get integration tests running in our Spring MVC project.
One of our components depends on the ViewResolver which gets autowired by Spring. It's configured in the test-context.xml:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
However, this gives me an NoUniqueBeanDefinitionException:
Caused by:
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.web.servlet.ViewResolver' available: expected single matching bean but found 2: org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.web.servlet.view.InternalResourceViewResolver#1
When I remove the InternalResourceViewResolver property from the test-context.xml, I get a
Caused by:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.web.servlet.ViewResolver' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
How can that happen?

Related

JNDI lookup failure

i would be grateful if someone can help me rectify the issue in my code. Not sure where I'm going wrong.
Currently my persistence.xml contains
<property name="hibernate.transaction.manager_lookup_class" value="#####.hibernate.JbossTSTransactionManagerLookup"/>
<property name="hibernate.current_session_context_class" value="jta"/>
along with
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="####"/>
<property name="jpaDialect" ref="jpaDialect"/>
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:comp/env/TransactionManager"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
Context initialization failed : org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [###XMLConfig.xml]: Invocation of init method failed; nested exception is org.springframework.transaction.TransactionSystemException: JTA TransactionManager is not available at JNDI location [java:comp/env/TransactionManager]; nested exception is org.springframework.jndi.TypeMismatchNamingException: Object of type [class com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple] available at JNDI location [java:comp/env/TransactionManager] is not assignable to [javax.transaction.TransactionManager]
Caused by: org.springframework.transaction.TransactionSystemException: JTA TransactionManager is not available at JNDI location [java:comp/env/TransactionManager]; nested exception is org.springframework.jndi.TypeMismatchNamingException: Object of type [class com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple] available at JNDI location [java:comp/env/TransactionManager] is not assignable to [javax.transaction.TransactionManager]
at org.springframework.transaction.jta.JtaTransactionManager.lookupTransactionManager(JtaTransactionManager.java:598)
Caused by: org.springframework.jndi.TypeMismatchNamingException: Object of type [class com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple] available at JNDI location [java:comp/env/TransactionManager] is not assignable to [javax.transaction.TransactionManager] at org.springframework.jndi.JndiTemplate.lookup()
at org.springframework.transaction.jta.JtaTransactionManager.lookupTransactionManager()
Looks like there is some issue with the classpath of your project. Check if there are two versions of the same dependency in your project. In my case I had multiple versions of the jboss-transaction jar in the classpath, keeping just one version of it fixed the issue for me. Check if there is any transitive dependency which is causing this issue which you can exclude in your maven pom.

Configure Spring bean by setting up the elastic 5.5.1 configuration settings and create a transport client bean

I am trying to use ElasticSearch Java API 5.5.1 and while trying to create a bean for PreBuiltTransportClient(TransportClient in ES 2.3) I am facing the below issue.
Error creating bean with name 'preBuildTransportClient' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Unsatisfied dependency expressed through constructor parameter 0: Could not convert argument value of type [org.elasticsearch.common.settings.Settings$Builder] to required type [org.elasticsearch.common.settings.Settings]: Failed to convert value of type [org.elasticsearch.common.settings.Settings$Builder] to required type [org.elasticsearch.common.settings.Settings]; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.elasticsearch.common.settings.Settings$Builder] to required type [org.elasticsearch.common.settings.Settings]: no matching editors or conversion strategy found
<bean id="settingsBean" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
<bean id="builderObj" class="org.elasticsearch.common.settings.Settings" factory-method="builder" />
</property>
<property name="targetMethod" value="put" />
<property name="arguments">
<map>
<entry key="cluster.name">
<value>mycluster</value>
</entry>
</map>
</property>
</bean>
<bean id="transportClient" class="org.elasticsearch.transport.client.PreBuiltTransportClient">
<constructor-arg name="settings" ref="esSettingsBuilderStep2" />
<constructor-arg name="plugins">
<null />
</constructor-arg>
</bean>
Any suggestion for creating a bean for PreBuiltTransportClient?
Created a class and used that as bean with proper arguments worked for me.

Configure JMX with Spring implementation of ehcache?

I'm trying to follow the articles here & here to implement JMX for ehCache. My app uses the Spring implementation however & the config entries below get this exception:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'managementService' defined in class
path resource [trs.application.finance.businessactivites.xml]:
Unsatisfied dependency expressed through constructor argument with
index 0 of type [net.sf.ehcache.CacheManager]: Could not convert
constructor argument value of type
[org.springframework.cache.ehcache.EhCacheCacheManager] to required
type [net.sf.ehcache.CacheManager]: Failed to convert value of type
'org.springframework.cache.ehcache.EhCacheCacheManager' to required
type 'net.sf.ehcache.CacheManager'; nested exception is
java.lang.IllegalStateException: Cannot convert value of type
[org.springframework.cache.ehcache.EhCacheCacheManager] to required
type [net.sf.ehcache.CacheManager]: no matching editors or conversion
strategy found
Does spring have an implementation of net.sf.ehcache.management.ManagementService I can use? If so how do I configure it so I can have JMX support for ehcache in my app.
Note, the "managementService" & "mbeanServer" beans are what I added to try & get ehcache to register with jmx. "myCacheManager" already exists in my spring config & seems to work fine, as far ehcache alone goes.
<bean id="managementService" class="net.sf.ehcache.management.ManagementService"
init-method="init"
destroy-method="dispose">
<constructor-arg ref="myCacheManager"/>
<constructor-arg ref="mbeanServer"/>
<constructor-arg index="2" value="true"/>
<constructor-arg index="3" value="true"/>
<constructor-arg index="4" value="true"/>
<constructor-arg index="5" value="true"/>
</bean>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true"/>
</bean>
<bean id="myCacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager">
<bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"/>
</bean>
</property>
</bean>
The problem is the way you wire your beans.
You do not want to use myCacheManager in the managementService, you really want to use the bean returned and passed as the cacheManager of myCacheManager.
So I suggest moving the following:
<bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"/>
</bean>
to a top level bean so that it can be injected in managementService.

Configuration Issue during spring upgrade

Below is the issue i am facing during the spring upgrade.I feel the issue is with the doctype.Please suggest
Bean 'cdqiPerformanceMonitor'; nested exception is
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Old 1.x 'singleton' attribute in use - upgrade to
'scope' declaration
Offending resource: ServletContext resource [/WEB-
INF/applicationContext.xml]
Below is the application context xml
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="cdqiPerformanceMonitor"
class="com.tms.cdqi.framework.aop.interceptor.CDQIPerformanceMonitorInterceptor" />
<bean id="cdqiApplicationContextFactory"class="com.tms.cdqi.framework.context.CDQIApplicationContextFactoryImpl" />
<bean id="commandInvoker"class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean"
lazy-init="true">
<property name="jndiName">
<value>ejb/CommandInvokerLocal</value>
</property>
<property name="businessInterface">
<value>
com.tms.cdqi.application.command.invoker.CommandInvoker
</value>
</property>
</bean>
</beans>
Below is the stack trace
listener org.springframework.web.context.ContextLoaderListener
failed:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unexpected failure during bean definition parsing
Offending resource: ServletContext resource [/WEB-
INF/applicationContext.xml]
Bean 'cdqiPerformanceMonitor'; nested exception is
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Old 1.x 'singleton' attribute in use - upgrade to
'scope' declaration
Offending resource: ServletContext resource [/WEB-
INF/applicationContext.xml]
See SPR-12167. Spring no longer accepts singleton="true", so you must use scope="singleton" instead.

replaced-method question in spring 3

Excuse me. I'm a beginner of spring. Now, there's some question in it.
I'm reading Spring in action and try the code in MyEclipse. But when I try the code of replaced-method, there's a error.
<bean id="harry" class="com.springinaction.sprintidol.Magician">
<property name="magicBox" ref="magicBox" />
<property name="magicWords" value="Bippity boppity boo" />
</bean>
<bean id="magicBox" class="com.springinaction.sprintidol.MagicBoxImpl">
<replaced-method name="getContents" replacer="tigerReplacer" />
</bean>
<bean id="tigerReplacer" class="com.springinaction.sprintidol.TigerReplacer" />
This is the applicationContext.xml. And the exception as followed:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stevie' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter
All of the code come from the book. Why do I get the exception? And how to solve?
Thanks.
I found the reason. Because I didn't include the Spring 3.0 Persistence Core Libraries.Thanks all the same.

Resources