I'm trying to make webapp which should use thymeleaf with spring controllers. But I'd like to have some CDI ConversationScoped beans injected into my Spring controller. For now I managed to configure CDI with my Spring application I when I tried to incject CDI bean into my controller it seems to work fine, but when I tried to inject Conversation bean it fails with error:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.enterprise.context.Conversation] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#javax.inject.Inject()}
In CDI 1.0 the conversation scope is tied to JSF. If you're not using JSF you won't be able to access the conversation scope. You could create another scope which mimics the conversation scope though.
Related
Is there any chance that CDI and spring dependency injection could co-exist. The problem started when I tried using JpaRepository interface.
I cannot remove beans.xml as it breaks a common jar implementation which uses CDI. I tried #Vetoed but it then fails to autowire my JpaRepository interface in a service class. Does it mean that #Vetoed prevents the bean from being managed by spring also?
I am looking for an idea so that i could use CDI to manage some beans and spring to manage the rest.
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.
Is there any difference between Bean Injection and Dependency Injection in Spring, or are they the same?
Since the dependencies are beans in our context, yes we can say that they are the same.
Any dependency that is managed by Spring is called a Spring Bean. When you register a type in Spring, when it is used as a dependency in other objects, it is injected by Spring.
On the other hand, Dependency Injection doesn't need a container like Spring. When you have a method that takes arguments, that argument is a dependency, which is a form of dependency injection instead of hard code the value of the argument in your method.
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
I have a third party lib which is exposing declarative service. But I have a spring bean class.
How do I inject this declarative service into my spring bean class?
You must declare this service also as a bean so it can be managed by spring.