WELD-001408 Unsatisfied dependencies for type [DataSource] with qualifiers - eclipse

I have the following that is causing the subjected error message in APP-A
#Inject #CtcDB
private DataSource ds;
I'm using an identical pattern with APP-B which does not complain of this error.
When I hover over ds in Eclipse while holding down the ctrl key, I get the following context menu for APP-B
Open #Inject Bean Resource.ds
Open Declaration
Open Declared Type
but in the APP-A with the dependency error I only get
Open Declaration
Open Declared Type
// The Resources class is basically the same b/n both apps except the qualifier is #CommitmentDB for APP-B
public class Resources {
#Produces
#Resource(mappedName="java:jboss/datasources/myjndids")
#CtcDB
private DataSource ds;
// And my annotation
#Qualifier
#Retention(RUNTIME)
#Target({ METHOD, FIELD, PARAMETER, TYPE })
public #interface CtcDB{
}
I know CDI is active (I have a beans.xml in WEB-INF) because I have a POM dependency which contains some injectable beans. When hovering with the ctr key for those injections I get the expected context menu (in both apps)

OK I figured it out myself. In the Resources class I had the wrong import for DataSource
import javax.activation.DataSource; \\instead of
import javax.sql.DataSource;
I must have clicked on the wrong Eclipse Quickfix and imported the wrong package.

Related

Arango spring-data documentation no longer current. Not clear what you should do for new coding model

I am struggling with changes in the most current arangodb-spring-data project code that doesn't align with the older documentation.
Here is my refreshed gradle build dependencies
plugins {
id 'org.springframework.boot' version '2.2.0.RELEASE'
id 'groovy'
}
apply plugin: 'io.spring.dependency-management'
...
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
//implementation 'org.codehaus.groovy:groovy'
implementation group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.0-rc-1'
// testImplementation group: 'org.spockframework', name: 'spock-core', version: '1.3-groovy-2.5'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'com.arangodb:arangodb-spring-data:3.2.3'
implementation 'com.arangodb:arangodb-java-driver:6.4.1'
}
I have a arangoConfiguration class like this:
#Configuration
#EnableArangoRepositories(basePackages = [ "com.softwood.arango" ])
class ArangoConfiguration extends AbstractArangoConfiguration { //changed since 3.2.0
//class ArangoConfiguration {
#Override
public Builder arango() {
return new ArangoDB.Builder().host("localhost", 8529).user("root").password(null)
}
#Override
public String database() {
return "testDB"
}
}
However in the IDE it now shows that extends AbstractArangoConfiguration is deprecated. There is now an interface instead called ArangoConfiguration in my ArangoConfiguration class.
I tried changing the code to implements this interface and it doesn't work, as I get a bean dependency failure with ArangoOperations not being defined - which if you extend the deprecated abstract class doesn't happen. Spring fails on injecting the operations autowired bean - if you try and implement from the ArangoConfiguration interface in the copy of the demo code is here in github sample code.
My CrudRunner looks like this
#ComponentScan("com.softwood.arango")
public class CrudRunner implements CommandLineRunner {
#Autowired
private ArangoOperations operations
#Autowired
private OrganisationRepository orgRepo
#Autowired
private SiteRepository siteRepo
#Autowired
private OperatesFromManyRepository ownsRepo //edge relationship
....
The code works if I revert to the deprecated model approach - however I still get separate unrelated warning with a reflection problem using Java 11.0.5. This doesn't stop it working but the code base is doing something that Java 11 doesn't like.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/C:/Users/will/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.2.0.RELEASE/e0e1b3c304f70ed19d7905975f6f990916ada219/spring-core-5.2.0.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
There is nothing updated on the arangodb-spring-data usage documentation to reflect the go forward way with the new interface.
What should the latest version V.3.0+ versions look like?
The Java 11 warning is a problem - but the code still seems to run but will need a fix; it doesn't happen on Java 8.
If any one knows the new approach can they share that, else I'll have to post across on the Git project pages.
The documentation has been updated: https://github.com/arangodb/docs/pull/541
Furthermore ArangoConfiguration does not add anything to AbstractArangoConfiguration, as you can see here: https://github.com/arangodb/spring-data/blob/4ae3130af345a0314a215605aa38fb7c88d41d5b/src/main/java/com/arangodb/springframework/config/AbstractArangoConfiguration.java, and it should work exactly in the same way (except for the deprecation warning). So maybe your injection problems are due to some other reason.
Also: illegal reflective access warnings when using Java 11 are not due to Spring Data Arango, but from the Spring Framework: https://github.com/spring-projects/spring-framework/issues/22674

Eclipse custom #NonNull annotation ignored

I would like to use the "null analysis" feature of Eclipse but I would rather use the javax.annotation.Nonnull annotation than the org.eclipse.jdt.annotation.NonNull annotation. I can't seem to get Eclipse to recognize any custom annotations I configure.
I'm using Eclipse Luna 4.4.2.
I created a new test project that contains only the following class:
package org.example;
import javax.annotation.Nonnull;
public class OmgNulls {
public static void main(String[] args) {
#Nonnull String test = null;
System.out.println(test);
}
}
My compiler settings are configured to use the javax annotations:
My project's includes the checker-1.8.10 JAR to provide the annotations.
With these settings, Eclipse reports 0 errors.
If I check "Use default annotations for null specifications" and change my test class to use Eclipse's annotation, I get:
Anyone know what I'm doing wrong or is this an Eclipse bug maybe?
I've also tried the jsr305 JAR from google instead of checker in case that was an issue but that didn't help.

Eclipse not recognizing slf4j or logback Logger class methods

I have recently been tasked to begin architecting a new Spring 3 MVC project (I am quite the noob in this regard). Having set up most of the POC project in Kepler, I have:
a prototype webapp (HelloWorld style) that is deployable and
working in (an external) Tomcat7.
Logback configured and reporting to the console:
...
12:46:21.916 [http-apr-8080-exec-5] TRACE o.s.w.s.v.InternalResourceViewResolver - Cached view [home]
12:46:21.916 [http-apr-8080-exec-5] DEBUG o.s.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'home'; URL [/WEB-INF/view/home.jsp]] in DispatcherServlet with name 'sample'
12:46:21.916 [http-apr-8080-exec-5] TRACE o.s.web.servlet.view.JstlView - Rendering view with name 'home' with model {name=lingxotika.org} and static attributes {}
12:46:21.916 [http-apr-8080-exec-5] DEBUG o.s.web.servlet.view.JstlView - Added model object 'name' of type [java.lang.String] to request in view with name 'home'
12:46:21.921 [http-apr-8080-exec-5] DEBUG o.s.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/view/home.jsp] in InternalResourceView 'home'
12:46:21.957 [http-apr-8080-exec-5] TRACE o.s.web.servlet.DispatcherServlet - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade#1bb3db1b
12:46:21.960 [http-apr-8080-exec-5] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
12:46:21.960 [http-apr-8080-exec-5] TRACE o.s.w.c.s.AnnotationConfigWebApplicationContext - Publishing event in WebApplicationContext for namespace 'sample-servlet': ServletRequestHandledEvent: url=[/codetutr/home/]; client=[127.0.0.1]; method=[GET]; servlet=[sample]; session=[0108E781644C1268FD92C11BD78888FB]; user=[null]; time=[87ms]; status=[OK]
but when I go into my code into use the Logger class methods (I've tried both
org.slf4j.Logger and ch.qos.logback.classic flavors), Eclipse
does not recognize the methods in the Logger instance:
package org.lingxotika.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class SampleController {
static final Logger log = LoggerFactory.getLogger(SampleController.class);
log.info("Hit Controller..."); // Error is here
#RequestMapping("home")
public String loadHomePage(Model model) {
model.addAttribute("name", "lingxotika.org");
return "home";
}
}
The Eclipse Code Assist after typing log. shows the following options (sorry, can't post screenshots yet):
new - create new object
nls - non-externalized string marker
runnable - runnable
toarray - convert collection to array
To sum, I have seen examples here and here that suggest this isn't a limitation of Spring or my admitted lack of competency with it, but an Eclipse issue that I am overlooking. I avoided posting what could be irrelevant information, but am happy to supply any further code, logs, or config examples. Any help would be appreciated.
Seems like you dont have the slf4j api jar in your project.
Since it is working in tomcat, perhaps tomcat is using a "provided" jar, ie: one that is part of the tomcat application.
If you are using maven, you need to have the following dependency in you pom:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

Why does #Inject fail when adding CDI Extension?

I'm trying to write a CDI extension. As soon as I add the META-INF/services/java.enterprise.inject.spi.Extension file, all injections are failing with the message WELD-001408 Unsatisfied dependencies for type... . The strange thing is, the extension-file can also be empty and this error still happens. When I remove the file, everything is working as expected.
I'm using Glassfish 1.3.2.2.
Does anyone have an idea why this happens? I did not find anyything on google.
//Edit: Code example
I have a REST-resource and I inject a class SomeClass into that resource (see example)
#Path("test")
#Produces("text/plain")
public class SomeResource{
#Inject private SomeClass someclass;
}
This works totally fine when the META-INF/services/java.enterprise.inject.spi.Extension- file does not exist. As soon as I add the file, I get the WELD-001408 Unsatisfied dependencies... Exception. Even when the file is empty. Is this a Glassfish-Bug?

JaxB #XmlRootElement result in "Cannot resolve xml element declaration"

I was using JAXB as DTO to set a stable interface between Server and Clients. Anyways this doesn't matter. What matters is I created a set of classes that result in the following compile error.
Cannot resolve XML element declaration with namespace 'namespace' and
name 'name' in this context
Eclipse underlined "name" inside quotes as an error. This class is manually created instead of xjc generated.
#XmlRootElement(name="name", namespace="namespace")
#XmlType(name="")
public class UserDTO {
private UserType userType;
#XmlElement
public UserType getDTO(){
return userType;
}
public void setDTO(UserType userType){
this.userType=userType;
}
}
where UserType is a xjc generated class
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "userType", propOrder = {
"userId",
"userName"
})
public class UserType {getter;setter}
So basically UserDTO is just a wrapper that wraps up sub jaxb types.
I'm not sure if it was platform dependent (which it shouldn't be), anyways, just to mention that this code worked perfectly on Netbeans, but when it come to Eclipse, the error prevented the compilation.
The Environment running the project was:
1. MacOsX Lion
2. JDK: 1.6.0_37
3. Eclipse Version: Juno with Package 1
4. JAXB Platform: Generic JAXB 2.1
Please anyone can share some idea?
ps: I added the JDK info and Libraries setting as Manuel suggested.
I faced this issue, you have more than one schema, at least two, both of them don't have namespace, just assign namespace to one of them.