spring statemachine data jpa sample issues - spring-boot

I am trying to get the spring statemachine data jpa sample working and I am unable to. I have created a sample github project here. So far, I have only added the necessary dependencies and getting this error:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.statemachine.data.StateRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound (DefaultListableBeanFactory.java:1493)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency (DefaultListableBeanFactory.java:1104)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency (DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject (AutowiredAnnotationBeanPostProcessor.java:585)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject (InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues (AutowiredAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean (AbstractAutowireCapableBeanFactory.java:1264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:483)

Maybe you already figured this out but you're missing jpa libs. Those can be added i.e. using spring-boot-starter-data-jpa

Related

Unable to Autowire brave.Tracer inside Spring boot Application

I am working on Spring boot application and I tried to Autowire Tracer object to get the traceId, but its raised the following exception. why??
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'brave.Tracer' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
I used the Tracer in a lot of projects and its always working with no issues!!
Spring boot container is not able to resolve the implementation of your autowired interface in this case. Please annotate your implementation class with spring stereotype annotations.
For e.g We provide #Reposiory for dao classes, #Service for service classes & #Component as a generic one. This will solve your problem. If you still face any issues, Just share your code snippet.

Spring OSGi - unable to autowire the class from external OSGi jar in WAB bundle

I am developing an application using Spring OSGi and IBM WebSphere liberty. I have one WAB bundle which has all controller classes and have another bundle which has all utility/service/dto/model classes.
I loaded the utility bundle to a shared repository and I am trying to autowire the class from the share repo bundle. The problem I am facing is, I am unable to autowire the class (Class is annotated with #Service) from external OSGi jar to WAB bundle. I am getting an exception during the autowire process, which says:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [x.y.z.CodeExternalAutowire] found for dependency [x.y.z.CodeExternalAutowire]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
I have verified that the external OSGi jar bundle and package are loaded but am unable to autowire the package class from the WAB. Appreciate if anyone can help me with this.

Spring initialization done outside the project

I have a java spring project . I see that one way of initialing the spring project is using this code in the main method.
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class);
ctx.scan("com.example.db.app");
ctx.refresh();
Is it possible to keep this outside a main method and then make a jar of this project. Add it as a dependency in pom.xml in other project and call the method which initializes the spring artifacts from there.
I tried doing it. I am getting an error.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemInformationRepositoryService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.example.db.app.service.ItemInformationRepositoryService.setItemInformationRepositoryService(com.example.db.app.repository.ItemInformationRepository); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.example.db.app.repository.ItemInformationRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
The exception message states:
No qualifying bean of type [com.example.db.app.repository.ItemInformationRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
This means that the class com.example.db.app.repository.ItemInformationRepository is not in the Spring context. Perhaps you were expecting Spring to discover this class as a result of your instruction to Spring to scan com.example.db.app? According to the Javadocs for AnnotationConfigApplicationContext.scan() ...
Perform a scan within the specified base packages.
#param basePackages the packages to check for annotated classes
So, in order for Spring to discover com.example.db.app.repository.ItemInformationRepository you must either:
Annotate it with org.springframework.stereotype.Component so that it is discovered by scan()
Register it in the same way as you are registering Config.class e.g. ctx.register(ItemInformationRepository.class);

Spring boot (1.3.6) + Hibernate(5.2.1) No qualifying bean of type [org.hibernate.SessionFactory] found for dependency:

While moving into micro-services from monolithic application, upon creating the micro-services using Spring boot (1.3.6) + Hibernate(5.2.1) we got an exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}.
But the same source code is running on hibernate(4.3.11). Please find the source code on
https://github.com/pandiaraj2/Spring-boot-1.3.6-Hibernate-5.2
What do I need to do to resolve this error?
Spring Boot 1.3.6 uses Spring 4.2.x, which doesn't support Hibernate 5.2. You also have to upgrade Spring to 4.3, e.g. by adding the following property in your pom.xml:
<properties>
<spring.version>4.3.1.RELEASE</spring.version>
</properties>
But it still might be, that some of the autoconfigurations are not working, because full Hibernate support in Spring Boot will only be introduced in Spring Boot 1.4, which is still in release candidate.
i guess you need to add #EnableJpaRepositories annotation on your main class DtcmwsApplication and also need to remove exclusion for hibernate-entitymanager

<jaxrs:client> not getting autowired

I am trying to build a restful client using jaxrs:client as defined in http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
In my test class I am getting org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.abc.service.ExportServiceTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.bankbazaar.service.ExportService com.abc.service.ExportServiceTest.exportClient; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.abc.service.ExportService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true), #org.springframework.beans.factory.annotation.Qualifier(value=exportClient)}
this is my spring config
However
exportClient=(ExportService)applicationContext.getBean("exportClient");
this works.
Thanks
Himangshu
The fully qualified classname for the two ExportService looks different com.abc.service.ExportService vs com.bankbazaar.service.ExportService. Fixing the two to point to the same name should fix the problem. Check the package name of the ExportService defined via applicationContext.getBean() to acertain the difference.

Resources