I am trying to implement Swagger for documentation, so that it picks both JSR 303 validation annotations and Spring Webflux based classes.
In Spring Boot project, I am currently using:
Spring Webflux framework for some classes
JSR 303 annotations on domain classes for Bean Validations and Constraints
Swagger integration with Spring Fox framework for generating OpenAPI documentation.
In build.gradle, following dependencies are used and I am able to make Spring Webflux + SpringFox work but only JSR 303 is giving issues:
springBootVersion = '2.0.2.RELEASE'
//JavaX-validation
'javax.validation:validation-api:2.0.0.Final',
'javax.el:javax.el-api:3.0.0',
'org.glassfish.web:javax.el:2.2.6'
//SpringFox-Swagger
'io.springfox:springfox-swagger2:2.9.2',
'io.springfox:springfox-spring-webflux:3.0.0-SNAPSHOT',
'io.github.swagger2markup:swagger2markup-gradle-plugin:1.3.3'
Here is the issue :
When below dependency is added to achieve "Spring Webflux + SpringFox + JSR 303",
**'io.springfox:springfox-bean-validators:2.9.2'**
I am getting the following error,
[WARN ] 2018-11-01 10:16:50.535 [main] SpringApplication - Unable to close ApplicationContext
java.lang.IllegalStateException: Failed to introspect Class
springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader#764c12b6]
at
org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:659) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at
org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:556 ) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.ge tTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:724) ~[spring- beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at
org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:861) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at
org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:810) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
Caused by: java.lang.NoClassDefFoundError:
org/springframework/web/servlet/HandlerMapping
at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:1.8.0_92]
at java.lang.Class.privateGetDeclaredMethods(Unknown Source) ~[?:1.8.0_92]
at java.lang.Class.getDeclaredMethods(Unknown Source) ~[?:1.8.0_92]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:641) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
... 20 more
Caused by: java.lang.ClassNotFoundException: org.springframework.web.servlet.HandlerMapping
at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_92]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_92]
Several blogs say that,SpringBoot version 2x doesn't support JSR 303. I am not sure but I tried to see it doesn't work.
Please advise.
Also, If JSR 303 is not supported currently, what other Validation annotations can be used apart from JSR 303 ?
I don't want to use Swagger core annotations, only because it is messing up code readability.
Add in your pom.xml:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
<scope>compile</compile>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webflux</artifactId>
<version>3.0.0</version>
</dependency>
And use the annotation:
#EnableSwagger2
In you swagger configuration.
Officially springfox doesn't support spring webflux(more informations you can read here: springfox issues).
But you can try SNAPSHOT version like this: webflux-swagger.
As I can see version greater than 2.3.2, support for bean validation annotations:pringfox-support-for-jsr-303.
Related
I exported DataFlow application to Runnable JAR file from Eclipse.
I get below exception when I run the command Desktop$java -jar mariadevconn.jar
Why is the current working directory of command line added to the Google Storage path? Thank you for your help.
org.apache.beam.runners.dataflow.options.DataflowPipelineOptions$StagingLocationFactory create
INFO: No stagingLocation provided, falling back to gcpTempLocation
java.lang.RuntimeException: Failed to construct instance from factory method DataflowRunner#fromOptions(interface org.apache.beam.sdk.options.PipelineOptions)
at org.apache.beam.sdk.util.InstanceBuilder.buildFromMethod(InstanceBuilder.java:233)
at org.apache.beam.sdk.util.InstanceBuilder.build(InstanceBuilder.java:162)
at org.apache.beam.sdk.PipelineRunner.fromOptions(PipelineRunner.java:52)
at org.apache.beam.sdk.Pipeline.create(Pipeline.java:142)
at com.masterconcept.cloud.dataflow.connector.MariaDBConnector.main(MariaDBConnector.java:98)
Caused by: java.lang.reflect.InvocationTargetException
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.apache.beam.sdk.util.InstanceBuilder.buildFromMethod(InstanceBuilder.java:222)
... 4 more
Caused by: java.lang.IllegalArgumentException: Expected a valid 'gs://' path but was given '/Users/henry/Desktop/gs:/hellodataflowfromhenry/temp/staging/'
at org.apache.beam.sdk.extensions.gcp.storage.GcsPathValidator.getGcsPath(GcsPathValidator.java:101)
at org.apache.beam.sdk.extensions.gcp.storage.GcsPathValidator.verifyPath(GcsPathValidator.java:75)
at org.apache.beam.sdk.extensions.gcp.storage.GcsPathValidator.validateOutputFilePrefixSupported(GcsPathValidator.java:60)
at org.apache.beam.runners.dataflow.DataflowRunner.fromOptions(DataflowRunner.java:237)
... 9 more
Caused by: java.lang.IllegalArgumentException: Invalid GCS URI: /Users/henry/Desktop/gs:/hellodataflowfromhenry/temp/staging/
at org.apache.beam.sdks.java.extensions.google.cloud.platform.core.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:191)
at org.apache.beam.sdk.util.gcsfs.GcsPath.fromUri(GcsPath.java:116)
at org.apache.beam.sdk.extensions.gcp.storage.GcsPathValidator.getGcsPath(GcsPathValidator.java:99)
... 12 more
Part of the code:
DataflowPipelineOptions options = PipelineOptionsFactory.fromArgs(argv).withValidation().as(DataflowPipelineOptions.class);
options.setGcpTempLocation("gs://hellodataflowfromhenry/temp");
options.setRunner(DataflowRunner.class);
....
pom.xml:
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
<version>2.2.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.cloud.dataflow</groupId>
<artifactId>google-cloud-dataflow-java-sdk-all</artifactId>
<version>2.2.0</version>
</dependency>
work directory:
Desktop$pwd
/Users/henry/Desktop
I have neo4j 2.2.5 community edition and java code on the same machine (windows 7), I an trying the following code to connect to neo4j (without HA)
Configuration config = new BaseConfiguration();
config.setProperty(Neo4jGraph.CONFIG_DIRECTORY, "C:\\Users\\mike\\Documents\\Neo4j");
config.setProperty("gremlin.neo4j.conf.cache_type", "none");
Graph toyGraph = Neo4jGraph.open(config);
but I am getting the following exception
Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, C:\Users\mike\Documents\Neo4j
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:334)
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:59)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:108)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:95)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:176)
at org.neo4j.tinkerpop.api.impl.Neo4jFactoryImpl.newGraphDatabase(Neo4jFactoryImpl.java:44)
at org.neo4j.tinkerpop.api.Neo4jFactory$Builder.open(Neo4jFactory.java:32)
at org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph.<init>(Neo4jGraph.java:130)
at org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph.open(Neo4jGraph.java:144)
at ca.concordia.orchestrator.test.TestNeo4j.main(TestNeo4j.java:33)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.extension.KernelExtensions#7c0edd8f' failed to initialize. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:489)
at org.neo4j.kernel.lifecycle.LifeSupport.init(LifeSupport.java:72)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:106)
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:330)
... 9 more
Caused by: java.lang.NoClassDefFoundError: org/apache/lucene/document/Fieldable
at org.neo4j.kernel.api.impl.index.NodeRangeDocumentLabelScanStorageStrategy.<init>(NodeRangeDocumentLabelScanStorageStrategy.java:71)
at org.neo4j.kernel.api.impl.index.LuceneLabelScanStoreExtension.newKernelExtension(LuceneLabelScanStoreExtension.java:73)
at org.neo4j.kernel.api.impl.index.LuceneLabelScanStoreExtension.newKernelExtension(LuceneLabelScanStoreExtension.java:39)
at org.neo4j.kernel.extension.KernelExtensions.init(KernelExtensions.java:66)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:483)
... 12 more
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.document.Fieldable
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 17 more
I have following dependencies in pom.xml
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-core</artifactId>
<version>3.0.1-incubating</version>
</dependency>
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>tinkergraph-gremlin</artifactId>
<version>3.0.1-incubating</version>
</dependency>
<!-- Neo4j -->
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>neo4j-gremlin</artifactId>
<version>3.0.1-incubating</version>
</dependency>
<!-- neo4j-tinkerpop-api-impl is NOT Apache 2 licensed - more information
below -->
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-tinkerpop-api-impl</artifactId>
<version>0.1-2.2</version>
</dependency>
Any idea what could be the problem ? Does Thinkerpop3 work with neo4j 2.2.5?
Looks like that there are problems with dependency versions in your setup.
If you look at neo4j-tinkerpop-api-impl - you can see that there is currently release for Neo4j 2.2.5 in master. But maven central has 2.2 version.
Ensure that you are using correct version of Neo4j dependencies everywhere.
In maven dependency tree can be helpful.
I have an embedded neo4j database (2.1.3) that I am using with Jython 2.7b3. I would like to be able to use the web admin provided by WrappingNeoServerBootstrapper.
My current code is:
from org.neo4j.server import WrappingNeoServerBootstrapper
from org.neo4j.server.configuration import ServerConfigurator
from org.neo4j.graphdb.factory import GraphDatabaseFactory
graphDb = GraphDatabaseFactory().newEmbeddedDatabase('data/')
config = ServerConfigurator(graphDb)
WrappingNeoServerBootstrapper(graphDb, config).start()
However when I try to start WrappingNeoServerBootstrapper I get a very long stack trace which ends on:
Caused by: java.lang.ClassNotFoundException: org.neo4j.server.webadmin.rest.JmxService
at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[na:1.7.0_67]
at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[na:1.7.0_67]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_67]
at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[na:1.7.0_67]
at java.lang.ClassLoader.loadClass(ClassLoader.java:425) ~[na:1.7.0_67]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.7.0_67]
at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ~[na:1.7.0_67]
at com.sun.jersey.api.core.ClassNamesResourceConfig.convertToSet(ClassNamesResourceConfig.java:118) ~[na:na]
... 51 common frames omitted
01:25:32.485 [main] WARN o.e.j.u.component.AbstractLifeCycle - FAILED org.eclipse.jetty.server.Server#53f6812e: javax.servlet.ServletException: org.neo4j.server.web.NeoServletContainer-1365105063#3cbbb0ac==org.neo4j.server.web.NeoServletContainer,-1,false
javax.servlet.ServletException: org.neo4j.server.web.NeoServletContainer-1365105063#3cbbb0ac==org.neo4j.server.web.NeoServletContainer,-1,false
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:563) ~[na:na]
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:351) ~[na:na]
Thankful for any ideas on what I missing?
WrappingNeoServerBootstrapper is deprecated, according to this link. You won't find a word about NeoServerBootstrapper in recent manuals...
the solution should be writing extensions or plugins for neoserver.
You'll need to include these dependencies if you haven't already -
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<version>${neo4j.version}</version>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<version>${neo4j.version}</version>
<type>jar</type>
<classifier>static-web</classifier>
<scope>compile</scope>
</dependency>
I have a simple EJB 3.1 project which uses Glassfish 3.1.2 as AS and Maven 3 for dependency management. In the pom.xml of ejb project I set the generateClient option to true. I successfully deployed my ear to the server and then I tried to create a simple standalone client. Here is the pom.xml of the client:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>duan</groupId>
<artifactId>ejb31-app-client</artifactId>
<version>1.0-SNAPSHOT</version>
<name>ejb31-app-client</name>
<description>my app client</description>
<dependencies>
<dependency>
<groupId>org.glassfish.main.appclient.client</groupId>
<artifactId>gf-client-module</artifactId>
<version>3.1.2</version>
<type>pom</type>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>tools</artifactId>
<groupId>com.sun</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>duan</groupId>
<artifactId>ejb31</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb-client</type>
</dependency>
</dependencies>
where ejb31 is my ejb project for which I client is generated.
The Java class used in my application client is:
public class Test {
private static HelloWorldBeanRemote helloWorldBean;
public static void main(String[] args) {
String jndiPath = "java:global/ejb31-ear-1.0/ejb31-ejb/HelloWorldBean";
try {
Context ctx = new InitialContext();
System.out.println("Looking up bean at: " + jndiPath);
helloWorldBean = (HelloWorldBeanRemote) ctx.lookup(jndiPath);
System.out.println("Found helloWorldBean:" + helloWorldBean);
System.out.println("Calling sayHello():");
String greeting = helloWorldBean.sayHello();
System.out.println("HelloWorldBean said:" + greeting);
} catch (NamingException e) {
System.err.println("Could not find HelloWorldBeanRemote!");
System.err.println("JNDI path used for lookup:" + jndiPath);
e.printStackTrace();
}
}
}
The application client is compiled without problem by Maven. If I run this from Eclipse I get this exception:
Caused by: java.lang.ClassNotFoundException: ro.duan.ejb.HelloWorldBeanRemote
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.sun.ejb.EJBUtils.getBusinessIntfClassLoader(EJBUtils.java:688)
at com.sun.ejb.EJBUtils.loadGeneratedRemoteBusinessClasses(EJBUtils.java:463)
at com.sun.ejb.EJBUtils.lookupRemote30BusinessObject(EJBUtils.java:414)
... 7 more
But then if I manually add ejb-client.jar to the build path it works like a charm. So my conclusion is that somehow ejb-client.jar is available at compile time, but not at runtime. Any thoughts on how to solve this?
Remove the following line:
<scope>compile</scope>
Read more about dependency scope at:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope
I'm trying to migrate an app to JBoss 7.1.1 Final. I was using mojarra 2.0.2 version, as can be seen in pom.xml:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.2</version>
<scope>provided</scope>
</dependency>
Using JBoss 7.1.1 Final jsf embedded version (jsf-impl-2.1.7-jbossorg-2), the AS show this Exception:
09:21:16,456 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC00001: Failed to start service jboss.deployment.subunit."Projeto316Aplicacao.ear"."Projeto316Apresentacao-1.0.0-SNAPSHOT.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."Projeto316Aplicacao.ear"."Projeto316Apresentacao-1.0.0-SNAPSHOT.war".POST_MODULE: Failed to process phase POST_MODULE of subdeployment "Projeto316Apresentacao-1.0.0-SNAPSHOT.war" of deployment "Projeto316Aplicacao.ear"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885) [rt.jar:1.6.0_07]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) [rt.jar:1.6.0_07]
at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_07]
Caused by: java.lang.NoClassDefFoundError: javax/faces/model/DataModel
at java.lang.Class.getDeclaredConstructors0(Native Method) [rt.jar:1.6.0_07]
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389) [rt.jar:1.6.0_07]
at java.lang.Class.getConstructor0(Class.java:2699) [rt.jar:1.6.0_07]
at java.lang.Class.getConstructor(Class.java:1657) [rt.jar:1.6.0_07]
at org.jboss.as.web.deployment.jsf.JsfManagedBeanProcessor.deploy(JsfManagedBeanProcessor.java:108)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 5 more
Caused by: java.lang.ClassNotFoundException: javax.faces.model.DataModel from [Module "deployment.Projeto316Aplicacao.ear:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) [rt.jar:1.6.0_07]
... 11 more
Someone, please, knows why this occours and how to solve it?
Thanks
The solution for the java.lang.NoClassDefFoundError: javax/faces/model/DataModel exception in JBoss AS 7.1.1.Final is exactly what #BalusC said before:
Look like a bug in JBoss classloading:
community.jboss.org/thread/177061 If you provide JSF API/impl in
EAR/lib (which is actually the wrong place), then it's solved. –
BalusC Jan 24 at 12:09
If you are using maven, just put
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<scope>compile</scope>
</dependency>
....
<defaultLibBundleDir>lib</defaultLibBundleDir>
An another solution (It is not a good practice) is replace the jar in jboss-as-7.1.1.Final\modules\com\sun\jsf-impl\main to another implementation of jsf specification.