-
Notifications
You must be signed in to change notification settings - Fork 152
Error running the application as WAR in tomcat 9 #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I haven't had the time to update this project to the latest versions of Spring Boot and |
Yes, I have upgraded everything to the latest. No problem running it as
JAR. Only WAR and this exception.
…On Sun, Dec 2, 2018, 07:44 Esteban Herrera ***@***.*** wrote:
I haven't had the time to update this project to the latest versions of
Spring Boot and graphql-spring-boot, but you only mention Spring Boot,
did you update graphql-spring-boot-starter and graphql-java-tools too?
Does it work when you run the application as a JAR or from an IDE?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#10 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADsS-2SirW4EmxwO3fDuKJeNSRLI_kzDks5u0xRugaJpZM4Y80JC>
.
|
Okay, so probably the problem is in the way you generate the WAR file. How you do it? |
Just tried. Doesn't help. Here is the runtime exception stack trace:
|
This is my pom.xml:
|
The guides provided in the URLs do not use graphql-spring-boot-starter which is causing the issue. I remove that dependency the exception disappears but there is no servlet to generate the graphql schema. Besides, I receive 302 status code when POSTing to the endpoint using GraphIQL. |
Hi @khteh. Sorry, I didn't have time to look at this issue until now. I remembered I deployed this project in Tomcat successfully, but now that I tried again, it didn't work. The application was throwing the exception you mentioned in the first comment (and I didn't update the project to the latest versions of Spring Boot and GraphQL). Anyway, a search led me to this issue, which refers to another issue that includes a fix that apparently it's not needed anymore. But it is. The application works for me now. I deployed it with the context Here's the class @SpringBootApplication
public class DemoGraphQlApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(DemoGraphQlApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoGraphQlApplication.class);
}
@Bean
public ServletContextAware endpointExporterInitializer(final ApplicationContext applicationContext) {
return new ServletContextAware() {
@Override
public void setServletContext(ServletContext servletContext) {
ServerEndpointExporter serverEndpointExporter = new ServerEndpointExporter();
serverEndpointExporter.setApplicationContext(applicationContext);
try {
serverEndpointExporter.afterPropertiesSet();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
}
@Bean
public GraphQLErrorHandler errorHandler() {
return new GraphQLErrorHandler() {
@Override
public List<GraphQLError> processErrors(List<GraphQLError> errors) {
List<GraphQLError> clientErrors = errors.stream()
.filter(this::isClientError)
.collect(Collectors.toList());
List<GraphQLError> serverErrors = errors.stream()
.filter(e -> !isClientError(e))
.map(GraphQLErrorAdapter::new)
.collect(Collectors.toList());
List<GraphQLError> e = new ArrayList<>();
e.addAll(clientErrors);
e.addAll(serverErrors);
return e;
}
protected boolean isClientError(GraphQLError error) {
return !(error instanceof ExceptionWhileDataFetching || error instanceof Throwable);
}
};
}
@Bean
public BookResolver authorResolver(AuthorRepository authorRepository) {
return new BookResolver(authorRepository);
}
@Bean
public Query query(AuthorRepository authorRepository, BookRepository bookRepository) {
return new Query(authorRepository, bookRepository);
}
@Bean
public Mutation mutation(AuthorRepository authorRepository, BookRepository bookRepository) {
return new Mutation(authorRepository, bookRepository);
}
@Bean
public CommandLineRunner demo(AuthorRepository authorRepository, BookRepository bookRepository) {
return (args) -> {
Author author = new Author("Herbert", "Schildt");
authorRepository.save(author);
bookRepository.save(new Book("Java: A Beginner's Guide, Sixth Edition", "0071809252", 728, author));
};
}
} Apparently, the method And my <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>DemoGraphQL</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!--<packaging>jar</packaging>-->
<packaging>war</packaging>
<name>DemoGraphQL</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!--<version>1.5.9.RELEASE</version>-->
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>9</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<!--<version>3.10.0</version>-->
<version>5.0.2</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<!--<version>3.10.0</version>-->
<version>5.0.2</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-tools</artifactId>
<!--<version>4.3.0</version>-->
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- marked the embedded servlet container as provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project> I generated the WAR file with Hope it helps. |
Unfortunately it doesn't work for me here. I am using Java 11 Tomcat 9. I juet get the similar exception with different symbol now pointing to the added bean "endpointExporterInitializer":
|
Oh sorry, I reviewed my version of Tomcat, it's 8.5. I downloaded Tomcat 9 and yes, it doesn't work. Well, I guess we should have to wait for the issue you opened in the graphql-java-kickstart project to be resolved. |
Thanks @eh3rrera |
I managed to make it work with tomcat version 9.0.8, as I mentioned in the following comment, I hope it helps. |
Thanks @adexerivera! 👍 |
I use Spring Boot 2.1.0.RELEASE to build and install the application as WAR format on Tomcat9 and bump into the following exception when tomcat restarts:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverEndpointExporter' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available
Any advice and insight is appreciated
The text was updated successfully, but these errors were encountered: