In trying to create a demo Spring-MVC application, I'm running into an issue on startup:
ConversionNotSupportedException: Failed to convert property value of type org.apache.commons.dbcp.BasicDataSource to required type org.apache.tomcat.dbcp.dbcp2.BasicDataSource for property dataSource; nested exception is java.lang.IllegalStateException: Cannot convert value of
type [org.apache.commons.dbcp.BasicDataSource] to required type [org.apache.tomcat.dbcp.dbcp2.BasicDataSource] for property dataSource: no matching
editors or conversion strategy found
My question is, why does Tomcat think it needs to convert the BasicDataSource when it's defined in the applicationContext.xml file as
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
I can't see where it's getting that from...
I took the Captain-Kirk approach to solving this problem: I changed the parameters of the situation. Instead of trying to figure out why my new demo application, I copied an existing app then slowly changed and deleted things so that I got to my demo application. A more laborious approach, for sure, but I achieved my results ultimately...
Related
Im trying to follow the guide for Hybris123 version 19.05, but when creating new services I get a problem where the spring framework does not recognize my service.
I tried to change the neme of the variable but honestly Im not sure what to do.
The errorIm getting is "org.springframework.beans.FatalBeanException: Context hybris Global Context Factory couldn't be created correctly due to, Error creating bean with name 'applicationEventMulticaster': Unsatisfied dependency expressed through method 'setAllDecorators' parameter 0; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [concerttours.service.impl.DefaultBandService] for bean with name 'defaultBandService' defined in class path resource [concerttours-spring.xml]; nested exception is java.lang.ClassNotFoundException"
The code Im using in spring is:
<alias name = "defaultBandService" alias = "DefaultBandService"/>
<bean id = "defaultBandService" class = "concerttours.service.impl.DefaultBandService" >
<property name = "bandDAO" ref = "bandDAO" />
</bean>
And when I use the IDE for looking a file with the name DefaultBandService it recognizethe service that Im trying to use but the spring framework does not. In the service tried to use a spring Tag like component but it didnt work.
I expect spring to recgonize the bean and let me run the hybris server
Use your IDE to look for the class(i.e DefaultBandService).
Check the package of the class(most probably the first line of the file).
Make sure that the package is specified correctly in your spring xml File.
Make sure that the class is in the same extension as the Spring file. If it is not, then a dependency needs to be added in extensioninfo.xml.
Run "ant clean all" and start the Server again.
I have a application with spring 2.5.6 that uses spring jms:listener-container
<jms:listener-container concurrency="25" acknowledge="auto"
connection-factory="jmsCachingConnectionFactory" cache="none">
I works perfectly but now I need do externalize the concurrency value in a properties file. I already have others properties being loaded without error.
I tried the below code:
<jms:listener-container concurrency="${spring.jms.concurrency}" acknowledge="auto"
connection-factory="jmsCachingConnectionFactory" cache="none">
But it prints a sort of a parsing error:
[2018-06-25 17:36:05,292] ERROR [MSC service thread 1-1] context.ContextLoader => initWebApplicationContext: (ContextLoader.java:215) - Context initialization failed: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Invalid concurrency value [${spring.jms.concurrency}]: only single maximum integer (e.g. "5") and minimum-maximum combo (e.g. "3-5") supported.
Offending resource: class path resource [app-context.xml]; nested exception is java.lang.NumberFormatException: For input string: "${spring.jms.concurrency}"
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
Also tried to create a String bean and load the parameter then inject into the listener like below, but it print the same error
<bean id="concurrency" class="java.lang.String" >
<constructor-arg value="${spring.jms.concurrency}" />
</bean>
Is there a way to externalize/parametrize the concurrency value in the spring jms listener-container.
PS. Currently using spring 2.5.6 and cannot upgrade it right now.
I'm training about the combo Restlet/Spring but there are some things i still don't understand... I hope you can help me.
In fact, i'm trying to the use Inject dependancies systeme of Spring with Restlet (Like in this tutorial : http://restlet.com/technical-resources/restlet-framework/guide/2.3/introduction/getting-started/maven-spring). So I tried to do it myself but that didn't work. My code returns this exception :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'basecampComponent' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Cannot resolve reference to bean 'basecampAppliction' while setting bean property 'defaultTarget'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'basecampAppliction' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'root' of bean class[com.mycompany.restlet.basecamp.application.BaseCampApplication]:
Bean property 'root' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
So i was looking for the file "ApplicationContext.xml" and this is his content :
<bean id="basecampComponent" class="org.restlet.ext.spring.SpringComponent">
<property name="defaultTarget" ref="basecampAppliction" />
</bean>
<bean id="basecampAppliction">class="com.mycompany.restlet.basecamp.application.BaseCampApplication">
<property name="root" ref="router" />
</bean>
<!-- Define the router -->
<bean name="router" class="org.restlet.ext.spring.SpringBeanRouter" />
Someone has an idea where could I look for a way to debug this ?
By the way, i'm in Java 1.8.0_60.
Thanks for all your helps.
Benjamin
After looking for some informations over the web, i've a hypothesis how I solved this.
On this link (Spring & Restlet : 100% XML configuration?), he's binding the router with the property "inboundroot" of Application. So I think there's a minimal changed (not noticed in the tutorial). In fact, i tried the project proposed in the archive (doesn't work) and the way you code yourself the tutorial. This is again two solutions.
The final solution consists so by changing the name of the property to "inboundroot" to "root".
"Never trusts the tuto"
Thanks for the time you took to help me.
I think that there is no root attribute in the Application class. You should add one in your BaseCampApplication class and use it to configure your application (see createInboundRoot method), as described below:
public class BaseCampApplication extends Application {
private Restlet root;
public Restlet createInboundRoot() {
return root;
}
public void setRoot(Restlet root) {
this.root = root;
}
}
Hope it helps you,
Thierry
I am working on an application where I have two classes both implementing a common interface. So in time of bean declaration, I am going to mark one of them primary in my app-context.xml file. I can achieve this by simply declaring the primary bean like this:
<bean id="oracleImpl" class="com.me.dao.OracleImpl" primary="true">
</bean>
Now I don't want to hard code which of the beans is going to be the primary bean, rather want to read the true/false value from a properties file. So I went like this:
<context:property-placeholder location="classpath:jdbc.properties"/>
<bean id="oracleImpl" class="com.me.dao.OracleImpl" primary="${oracle.primary}">
</bean>
<bean id="pgsqlImpl" class="com.me.dao.PgsqlImpl" primary="${pgsql.primary}">
</bean>
The values of oracle.primary and pgsql.primary are defined in the file jdbc.properties along with other jdbc (non-boolean) properties.
But it doesn't work and says, "'${oracle.primary}' is not a valid value for 'boolean'"
I have a feeling it is something to do with the xsd validators. Browsing through this site and google gave me this much idea, but got no real solution. Can any body help?
This will not work.
As of 3.2.5.RELEASE only the following bean definition elemets support property placeholder:
parent name
bean class name
factory bean name
factory method name
scope
property values
indexed constructor arguments
generic constructor arguments
See the BeanDefinitionVisitor's visitBeanDefinition method for the details. This method is used by the PlaceholderConfigurerSupport.
I would recommend you to create a feature request in the spring issue management system.
PS: if you create an issue please add a comment to the issues url.
I'm working on an update version of grail-oauth-plugin that support last spring-oauth
My plugin version works good and I have implemented a workin oauth2 server.
But now I want to add a custom-grant defined like this
def doWithSpring = {
myTokenGranter(MyTokenGranter)
xmlns oauth:"http://www.springframework.org/schema/security/oauth2"
oauth.'authorization-server'( /* ... many definitions here ... */){
/* ... many definitions here ... */
oauth.'custom-grant'('token-granter-ref': "myTokenGranter")
}
}
But I get an exception telling me:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myTokenGranter'
But the bean myTokenGranter is defined as you can see. And If I remove the custom-grant definition the project starts and I can access the myTokenGranter bean.
Looking to a fullstack trace I see that the exception occur in the spring oatuh2 server bean definition parse AuthorizationServerBeanDefinitionParser.java in the line where it try to find my bean
parserContext.getRegistry().getBeanDefinition(customGranterRef);
where customGranterRef = "myTokenGranter"
so I suspect there is a bug in Spring Ouath or in Grails BeanBuilder that does not let my "myTokenGranter" to be visible in the server parser. Or making some error in grails bean definition DSL.
Thank you for your interest.
Debugging the app more deeply I have found that the problem probably is in how grails BeanBuilder work in translating namespaced spring DSL.
If I debug the point where my bean is checked (in AuthorizationServerBeanDefinitionParser.java)
at row
parserContext.getRegistry().getBeanDefinition(customGranterRef);
if I check che result of
parserContext.getRegistry().getBeanDefinitionNames()
it show me only this beans
[org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.annotation.internalCommonAnnotationProcessor
org.springframework.context.annotation.internalPersistenceAnnotationProcessor
org.springframework.aop.config.internalAutoProxyCreator
org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0
org.springframework.transaction.interceptor.TransactionInterceptor#0
org.springframework.transaction.config.internalTransactionAdvisor
oauth2TokenGranter
oauth2AuthorizationCodeServices
oauth2AuthorizationRequestManager]
And not all other decleared beans...
The problem exist even if I move the ouath server declaration inside resources.xml, keeping my custom token granter bean declaration inside resources.groovy.
But the problem solves if I move the custom token bean declaration inside resources.xml.
I don't really know how the BeanBuilder DSL works, but it seems like the problem is there if there is a problem (your example works just fine in XML). Can you do it in two steps, so the bean definition for myTokenGranter is definitely available when the OAuth2 namepsace is handled?
Solved hacking Spring Security Oauth
see this commit