CassandraTemplate Autowire - spring-data

I try to test out cassandra for my storage and maybe changing it from mongo.
I can't manage to autowire CassandraTemplate into my service getting.
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.data.cassandra.core.CassandraTemplate] 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)}
I have test creating the bean via xml and #Configuration, this application is an big monolithic application with dependency to several spring-data projects, I don't know if that is related to the problem
mvn dependency:tree | grep spring-data
[INFO] +- org.springframework.data:spring-data-jpa:jar:1.4.1.RELEASE:compile
[INFO] | \- org.springframework.data:spring-data-commons:jar:1.6.1.RELEASE:compile
[INFO] +- org.springframework.data:spring-data-mongodb:jar:1.3.1.RELEASE:compile
[INFO] +- org.springframework.data:spring-data-cassandra:jar:1.4.4.RELEASE:compile
When I debug #Configuration creating I see that I ends up in the Bean creation method but still my Service can not autowire that bean
#Bean
public CassandraOperations cassandraTemplate() throws Exception {
return new CassandraTemplate(session().getObject());
}
#Autowired
public CacheServiceScylla(CassandraTemplate cassandraTemplate) {
this.cassandraTemplate = cassandraTemplate;
}
I do not have any problem to to this with another application that is build with spring-boot.

Related

Wildfly 14 CDI: WELD-001408 on 3rd part JAR after migration from JBoss 7

We are migrating a few old systems written in Java 5, 6 and 7 to Java 8 and from JBoss 7 to Wildfly 14.
After the migration, I get all the time this kind of error:
WELD-001408: Unsatisfied dependencies for type InterfaceTypeConverterProvider with qualifiers #Named
I understand that from CDI 1.2 things changed and the #Inject don't work as it used to be and it need some refactoring.
I got many errors like this, some of them are classes in my own project that try to Inject other classes also inside my project, those ones I can fix.
The problem is: My project loads some classes that tries to inject other classes from outside, that are jar dependencies that I have no control over it and I can't change the code on those jars.
For example:
11:15:54,552 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC000001: Failed to start service jboss.deployment.unit."myApp-war-9.2-JAVA8-SNAPSHOT.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."myApp-war-9.2-JAVA8-SNAPSHOT.war".WeldStartService: Failed to start service at org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1728)
at org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1556)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.jboss.weld.exceptions.DeploymentException: Exception List with 46 exceptions:
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type InterfaceTypeConverterProvider with qualifiers #Named
at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] #Inject public thirdPartJar.converter.context.AbstractConverter.setTypeConverterProvider(#Named InterfaceTypeConverterProvider)
at thirdPartJar.converter.context.AbstractConverter.setTypeConverterProvider(AbstractConverter.java:0)
WELD-001475: The following beans match by type, but none have matching qualifiers:
- Managed Bean [class thirdPartJar.converter.context.TypeConverterProvider] with qualifiers [#Any #Default]
The error shows the problem in the class thirdPartJar.converter.context.AbstractConverter and I can't touch the code on that one... so, what should I do ?
Is it possible to downgrade Wildfly Weld or force it to use an older version of CDI ?
This is my beans.xml with the discover all but it still can't find the implementations.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.2" bean-discovery-mode="all">
</beans>
The beans.xml always only applies to the archive it's in (be it jar or war). So you're setting the bean-discovery-mode only for your own archive, not for the 3rd party one.
Easiest option: Repackage the 3rd party jar and include a fitting beans.xml.
Non-intrusive option: Write a producer that supplies the expected beans. Normally, this can be a simple method:
#Produces
#Named
public InterfaceTypeConverterProvider createInterfaceTypeConverterProvider() {
return new InterfaceTypeConverterProvider();
}
I take it that there is no injection within the class. Otherwise it should already have been cdi enabled.

Jhipster in Eclipse STS

I created a project 3.6.1 Jhipster(Gradle)
To debug the back-end import the project STS 3.8.1.
From the "Boot Dashboard" tab to run the application.
I get the following error:
[2m2016-10-06 14:14:51.306[0;39m [31mERROR[0;39m [35m32187[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mo.s.boot.SpringApplication [0;39m [2m:[0;39m Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'categoriaResource': Unsatisfied dependency expressed through field 'categoriaMapper': No qualifying bean of type [com.abalia.atletico.service.mapper.CategoriaMapper] found for dependency [com.abalia.atletico.service.mapper.CategoriaMapper]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#javax.inject.Inject()}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.abalia.atletico.service.mapper.CategoriaMapper] found for dependency [com.abalia.atletico.service.mapper.CategoriaMapper]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#javax.inject.Inject()}
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.abalia.atletico.service.mapper.CategoriaMapper] found for dependency [com.abalia.atletico.service.mapper.CategoriaMapper]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#javax.inject.Inject()}
It is a new project with three entities.
If I run the console is doing well, but I need to debug.
Not if I add some plugin or configuration to Eclipse STS
.yo-rc.json:
{"generator-jhipster": {
"jhipsterVersion": "3.6.1",
"baseName": "atletico",
"packageName": "com.aaa.bbb",
"packageFolder": "com/aaa/bbb",
"serverPort": "8080",
"authenticationType": "jwt",
"hibernateCache": "hazelcast",
"clusteredHttpSession": "hazelcast",
"websocket": "spring-websocket",
"databaseType": "sql",
"devDatabaseType": "postgresql",
"prodDatabaseType": "postgresql",
"searchEngine": "elasticsearch",
"buildTool": "gradle",
"enableSocialSignIn": true,
"jwtSecretKey": "dabb542aa2359c0c77c19bc6aeefc3af1700cec6",
"useSass": true,
"applicationType": "monolith",
"testFrameworks": [
"gatling",
"cucumber",
"protractor"
],
"jhiPrefix": "jhi",
"enableTranslation": true,
"nativeLanguage": "es",
"languages": [
"es",
"en"
]
}
}
This seems to be a problem with the generated output.
Following these instructions, what you need to do is:
Add apt generated source folder to build path
When using buildship gradles default outputfolder is filtered and not visible in your workspace. Therefore you need to remove it from eclipse’s resource filter setting.
Right click on your project and select Properties
Select Resources
Remove the entry build
Select Java Build Path
Click Add Folder...
Check the path build/generated/source/apt/main
Make sure the new source folder contains the correctly generated mapper implementations when running JHipster via eclipse.

Spring data JPA compatibility issue: Error creating bean with name 'jpaContext'

When I've adapted 'io.spring.platform:platform-bom:2.0.1.RELEASE'
As a result,
Spring Data JPA was upgraded to 1.9.2.RELEASE from 1.4.3.RELEASE
and Spring Data Common was upgraded to 1.11.2.RELEASE from 1.6.3.RELEASE
Now, the JBoss EAP 6.2 raised the following complain during deployment
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'jpaContext': Unsatisfied dependency expressed through constructor argument with index 0 of type [java.util.Set]: : No qualifying bean of type [javax.persistence.EntityManager] found for dependency [collection of javax.persistence.EntityManager]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {};
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] found for dependency [collection of javax.persistence.EntityManager]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
Build Environment
Gradle 2.9
Build time: 2015-11-17 07:02:17 UTC
Build number: none
Revision: b463d7980c40d44c4657dc80025275b84a29e31f
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_60-ea (Oracle Corporation 24.60-b09)
OS: Windows 7 6.1 amd64
Any help in this regard will be highly appreciated.

Running JUnit Test cases for Maven Project in Eclipse

I imported Maven project using maven eclipse plugins (m2e) and everything is fine.
But when I am running JUnit Test cases, I am getting below errors
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'be.belgacom.rosy.betty.manager.impl.ReservationManagerImplTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests.setDataSource(javax.sql.DataSource); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:374)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests.setDataSource(javax.sql.DataSource); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:589)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
... 26 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:547)
... 28 more
I am sure you might be suggesting to look at properties and other xml files configurations are correct or not.
If I import the same project into Eclipse as normal project, I am able to run the JUnit tests.
When I Import as Maven Projects, it's giving such errors.
Any idea, how do i solve this.
Your question lacks a lot of context. Have you ever run this from the command line with Maven? For example, have you run "mvn test" on the command line? Try this first then let us know if you receive the same error messages.
Your problem suggests that your POM doesn't contain the appropriate dependencies.

GWT doesn´t find my persistence.xml

I´m trying to save a simple user in my jpa hibernate db.
So I have a persistence.xml that I know that works (If I execute a simple test without deploying the gwt app).
The problem is that when I test it with my user interface, the persist method throw me the next error: (I think this is cause Doesn´t find the persistence.xml)
[ERROR] javax.persistence.PersistenceException: [PersistenceUnit: isw2.tasks] Unable to >configure EntityManagerFactory
... bla bla bla
[ERROR] Caused by: org.hibernate.HibernateException: Unable to get the default Bean >Validation factory
... more bla bla bla..
[ERROR] Caused by: java.lang.reflect.InvocationTargetException
...
[ERROR] Caused by: org.hibernate.HibernateException: Unable to build the default ValidatorFactory
[ERROR] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:383)
[ERROR] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:109)
.....
[ERROR] Caused by: javax.validation.ValidationException: Unable to find a default provider
[ERROR] at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264)
[ERROR] at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)
[ERROR] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.ja
This is the method I know that works:
`EntityManagerFactory emf = Persistence
.createEntityManagerFactory("isw2.tasks");
em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(u);
em.getTransaction().commit();
em.clear();
em.close();
`
And the most usefull for us, my proyect skeleton: (See that the persistence.xml file is there!)
I´m using maven and deploying the web app with the codehaus plugin.
Thanks in advance experts ;)
The exception message Unable to find a default provider suggests that hibernate cannot find a validation provider.
Is your Hibernate Validator jar on your runtime classpath? Also do note that you need to use Hibernate Validator 4 or later.