spring-data


Spring Elasticsearch data repository in Weld SE CDI - UnsatisfiedResolutionException


I am trying to inject Spring data repository (Elasticsearch in this instance) in SE application, using Weld SE.
Repository
public interface EmployeeRepository extends ElasticsearchRepository<Employee, String> {
List<Employee> findEmployeesByAge(int age);
List<Employee> findEmployeesByName(String name);
List<Employee> findEmployeesBySkillsIn(List skills);
}
Defining ElasticsearchTemplate:
#ApplicationScoped
public class ElasticsearchTemplateProducer {
#Produces
public ElasticsearchOperations createElasticsearchTemplate() {
Client client = null;
try {
client = TransportClient.builder().build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
} catch (UnknownHostException e) {
e.printStackTrace();
}
return new ElasticsearchTemplate(client);
}
}
Main (application is executed with org.jboss.weld.environment.se.StartMain) is as simple as:
public class Main {
#Inject
private Service repository;
public static void main(#Observes ContainerInitialized event){
}
}
Dependencies are:
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>2.0.2.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>spring-context</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>2.3.2.Final</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>1.2.2.Final</version>
</dependency>
</dependencies>
I've excluded spring context, but I get same exception whether or not I exclude context.
In resources\META_INF\beans.xml:
<?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.1" bean-discovery-mode="all"
xmlns:weld="http://jboss.org/schema/weld/beans">
<weld:scan>
<weld:exclude name="org.jboss.weld.**" />
</weld:scan>
And exception being thrown is:
javax.enterprise.inject.UnsatisfiedResolutionException: Unable to resolve a bean for 'org.springframework.data.elasticsearch.core.ElasticsearchOperations' with qualifiers [#javax.enterprise.inject.Default(), #javax.enterprise.inject.Any()].
at org.springframework.data.elasticsearch.repository.cdi.ElasticsearchRepositoryExtension.createRepositoryBean(ElasticsearchRepositoryExtension.java:75)
at org.springframework.data.elasticsearch.repository.cdi.ElasticsearchRepositoryExtension.afterBeanDiscovery(ElasticsearchRepositoryExtension.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:88)
at org.jboss.weld.injection.MethodInvocationStrategy$SpecialParamPlusBeanManagerStrategy.invoke(MethodInvocationStrategy.java:144)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:309)
at org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:124)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:287)
at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:265)
at org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:271)
at org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:260)
at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:154)
at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:148)
at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:53)
at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:42)
at org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl.fire(AfterBeanDiscoveryImpl.java:61)
at org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:423)
at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:83)
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:557)
at org.jboss.weld.environment.se.StartMain.go(StartMain.java:44)
at org.jboss.weld.environment.se.StartMain.main(StartMain.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:44)
at org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl.fire(AfterBeanDiscoveryImpl.java:61)
at org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:423)
at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:83)
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:557)
at org.jboss.weld.environment.se.StartMain.go(StartMain.java:44)
at org.jboss.weld.environment.se.StartMain.main(StartMain.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
What is the cause of this problem?
After a bit of debugging, I've noticed that no beans are being stored in elasticsearchOperationsMap in CDI extension ElasticsearchRepositoryExtension during processing beans phase, which causes an exception to be thrown later.
For now, I am using a workaround.
I add annotation #NoRepositoryBean to interface:
#NoRepositoryBean
public interface EmployeeRepository extends ElasticsearchRepository<Employee, String>
And then use the following #Produces method:
#Produces
public EmployeeRepository getEmployeeRepository() {
Client client = null;
try {
client = TransportClient.builder().build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
} catch (UnknownHostException e) {
e.printStackTrace();
}
ElasticsearchRepositoryFactory elasticsearchRepositoryFactory = new ElasticsearchRepositoryFactory(new ElasticsearchTemplate(client));
return elasticsearchRepositoryFactory.getRepository(EmployeeRepository.class);
}

Related Links

Bean name is ambiguous matches same bean twice
Error upgrading to Mongo java driver 3.2.2
Spring Data Redis: Setting a Password
Spring Data QueryDSL predicate two table join specification
specification groupBy in query and pagination
Spring Repository: get number of deleted rows
SpringData PageImpl totalElements is wrong
Spring Data MongoDB. Custom #Query with current date
Spring Data - Mongo DB - search
How to query using fields of subclasses for Spring data repository
Spring Data Elasticsearch Parent/Child Document Repositories / Test execution error
DynamoDB FilterExpression find all foreign keys that contain a set of attributes
Toplink release UnitOfWork Resources
what is the difference between indexOps and #Indexed
Spring Data Neo4j - ORDER BY {order} fails
Spring data elasticsearch - Can't merge a non object mapping with an object mapping

Categories

HOME
spring-data
webview
user-interface
android-studio
opencart
yaml
dotnetnuke
seedstack
kendo-dropdown
redmine
risk-management
twitter-fabric
cryptography
gallery
dji-sdk
share
pyresttest
phpseclib
specifications
tfs2010
tup
roku
bellman-ford
fireloop
vimeo
feature-extraction
asp.net-core-1.0
global-variables
vertica
adobe-illustrator
raml
angular2-highcharts
generator
quantitative-finance
chronicle-queue
exchange-server-2010
raima
annotation-processing
django-import-export
adapter
dnsmasq
xmlunit
serversocket
grails-2.5
busboy
wdk
textmate2
code-rally
nanogallery
aurelia-cli
unification
xll
fluid-mac-app-engine
httphandler
moinmoin
bit-shift
music21
adblock
spongycastle
rightnow-crm
hibernate-ogm
skip-lists
android-webservice
aurelia-fetch-client
mongodb-aggregation
sesame
rcharts
front-camera
petsc
qtextedit
jpda
django-testing
nsdata
dpkg
declarative
powerpoint-2013
android-async-http
mnesia
teamviewer
highest
postal-code
wicked-gem
console.log
baseadapter
kognitio-wx2
thoughtworks-go
nesper
network-printers
csslint
sqlbindparameter
iosched
application-blocks
sensormanager
hints
dynamic-rdlc-generation
unicoins
mongo-jackson-mapper
android-authenticator
xcode4.5
arrow
trialware
fitch-proofs
sql-parametrized-query
servlet-container
3-tier
icicles
rational-unified-process
activex-exe
jvm-bytecode
error-detection
parentid

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App