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.
Related
I have a wird problem with Spring. I'm working on a small mvc application and after some work I'm faceing such a problem:
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'userServiceImpl' for bean class [com.(...).servlet3.UserServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [com.(...).service.UserServiceImpl]
This exception looks like sefl-explain but there is one thing wird: I do not have such class as [com.(...).servlet3.UserServiceImpl]. I used to have, but moved to another package. My structure looks like this:
Does anyone has faced such a problem?
You have to check get and set method in bean for path bean definition or path name seems duplicate.
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
I am using another application's service,since everything is already made and done.
My application is to use the interface class inside the application jar.
but something seem to be wrong when this code is called.
BeanFactory factory = new ClassPathXmlApplicationContext( "/Context-Controller.xml");
even if my Context-Controller.xml has this code
<context:component-scan base-package="com.package" />
My error.
Caused by:
org.springframework.beans.factory.NoSuchBeanDefinitionException:
No unique bean of type
[com.package.ServiceIamUsing] is
defined: Unsatisfied dependency of
type [interface
com.package.ServiceIamUsing]: expected
at least 1 matching bean
this is how i autowired it on my applciation.
public class MyAppDao implements IMyAppDao {
#Autowired
#Qualifier("serviceIamUsing")
private ServiceIamUsing serviceIamUsing;
//More codes here
}
jay, try the following:
- eliminate the forward-slash "/"
- in your application context xml file, try to import the application context from your external jar file if it has any --> import resource="classpath*:/META-INF/spring/*.xml"
let me know if it does/doesn't work.
Is there, in fact, an instance of ServiceIamUsing in the jar that is also Spring-annotated (#Component, #Service, etc.)? It's possible this is the case, but I'd like to clarify.
If not, does the jar expose a Spring context file you can import, thus adding the additional beans to your context for autowiring?