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

Spring Data Serialization of Embeddable with ManyToOne References
Register spring data repository interface as bean in a java configuration
Can Hibernate OGM Persistence Provider be used with Spring-data-jpa?
Spring Data MongoDB field projection problems
Spring Data Rest CrudRepository vs ReadOnlyRepository
Automatic PagingAndSortingRepository for #Entity in some packages
Spring Data and how to sort by a column not in an Entity
Couchbase with Spring data using spring config example
How to load spring application context even if Cassandra down
Spring-Data-Rest with Dynamic Automatic Repository
With Spring Data REST, how to make custom queries use the HATEOAS output format?
Create querydsl predicate from map
Exception using Spring Data JPA and QueryDsl via REST Controller
Spring Data Project - Status?
Wildfly 9 datasource spring jpa missing dependencies error on openshift
JSF2 + Spring 4 + CDI + Spring Data, good match?

Categories

HOME
class
opencart
shinyapps
dotnetnuke
d3.js
devexpress
haproxy
visual-studio-2010
histogram
iptables
joomla3.2
onvif
azure-graph-api
colors
smooks
android-externalstorage
jquery-select2-4
jodatime
bnf
pinterest
google-sites
salt-cloud
bazaar
pfobject
clr
adminlte
activeadmin
tableview
sqlplus
hdl
acl
dragula
marquee
onchange
spring-annotations
region
envoy
rust-cargo
rspec-rails
android-collapsingtoolbar
counting
devtools
android-canvas
ms-dos
variable-variables
unification
sspi
data-uri
coverage.py
asihttprequest
jenkins-slave
gestures
redisson
mongodb-aggregation
gnome-terminal
portability
stateless-session-bean
word-2016
zend-server
mifos
pjax
libharu
jpda
carmen
spring-mongo
cdo.message
node.js-connect
gnucash
jsr363
flush
ioexception
wepay
teensy
helm
godeps
perceptron
chicagoboss
cfwheels
pythonxy
hmisc
compositetype
scala-macros
tidyr
html-escape-characters
incron
lifetime
adwords-apiv201402
box2dweb
hyperloglog
meteor-collections
tabletools
jack
oxygene
map
cloo
apportable
insertion
axacropdf
tfs-sdk
handshake
sfinae
telerik-ajax
thejit
exponent
background-repeat
will-paginate
vows
kohana-auth
fragment-identifier
upshot
anonymous-types
uninstaller
powergui
acceleration
jvm-bytecode

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App