Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

CORS functionality cannot be disabled with property 'graphql.servlet.cors-enabled' #763

Closed
bvklingeren opened this issue Dec 20, 2021 · 11 comments
Labels

Comments

@bvklingeren
Copy link

Describe the bug

The GraphQLWebAutoConfiguration class contains a 'corsConfigurer' bean factory method which has a @ConditionalOnProperty annotation with the value of 'graphql.servlet.corsEnabled'. This does not match with the 'graphql.servlet.cors-enabled' config parameter which is the expected format of such a property and therefore it doesn't prevent the CorsFilter to be created when you define the 'graphql.servlet.cors-enabled' config parameter with the value 'false'.

To Reproduce
Steps to reproduce the behavior:

  1. Register config param 'graphql.servlet.cors-enabled' in e.g. application.properties with value 'false'
  2. Create a breakpoint at line 127 of GraphQLWebAutoConfiguration
  3. Start your SB app in debug mode
  4. The debugger stops at the breakpoint

Expected behavior
The breakpoint should not have been reached and therefore the CorsFilter should not have been created.

Screenshots
N/a

Desktop (please complete the following information):
N/a

Additional context
N/a

@BlasiusSecundus
Copy link

This seems to be a duplicate of #682, which was already resolved (although the fix is not yet in the latest release, only in snapshot version).

@bvklingeren
Copy link
Author

Ah yes, you're right. I'll be looking out for the new release then.

@kumaritian
Copy link

kumaritian commented Aug 19, 2022

The issue still exists in the spring-boot 2.7.1 version.

@oliemansm
Copy link
Member

@kumaritian I've just tested this using the reproduction script of the original reporter with v13.0.0 icw Spring Boot and can confirm it is actually solved. So you must be doing something differently or are experiencing some other kind of issue.

@kumaritian
Copy link

@oliemansm : In which Spring boot version the issue got resolved. Currently I am using 2.7.1 version.

@oliemansm
Copy link
Member

@kumaritian It's not a specific Spring Boot version. It's resolved in graphql-spring-boot, so you need to upgrade that to v13.0.0

@kumaritian
Copy link

kumaritian commented Aug 19, 2022

@oliemansm : After upgrading to V13.0.0 from V12.0.0, I am getting below error during application start up but with V12.0.0 there is no issue as application is started successfully.

          <dependency>
		<groupId>com.graphql-java-kickstart</groupId>
		<artifactId>graphql-spring-boot-starter</artifactId>
		<version>13.0.0</version>
	</dependency>
	<dependency>
		<groupId>com.graphql-java-kickstart</groupId>
		<artifactId>graphql-java-tools</artifactId>
		<version>13.0.0</version>
	</dependency>

Note:

  1. With <version>12.0.0</version> the application is started successfully.

Error
java.lang.IllegalStateException: Failed to introspect Class [graphql.kickstart.autoconfigure.editor.graphiql.GraphiQLAutoConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@22d8cfe0]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485) ~[spring-core-5.3.22.jar:5.3.22]
.....
....
....
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.2.jar:2.7.2]
at com.mt.amp.pot.service.aggregator.ServiceAggregatorApplication.main(ServiceAggregatorApplication.java:22) ~[classes/:na]
Caused by: java.lang.NoClassDefFoundError: org/springframework/web/reactive/function/server/RouterFunction
at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402) ~[na:na]
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2504) ~[na:na]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467) ~[spring-core-5.3.22.jar:5.3.22]
... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.web.reactive.function.server.RouterFunction
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
... 25 common frames omitted

Dependencies
dependencies_in_pom xml

@oliemansm
Copy link
Member

This should be a separate discussion in Q&A instead of hijacking this issue for this problem. It's not related. Remove the graphql-java-tools dependency. graphql-spring-boot-starter pulls in the correct version.

@kumaritian
Copy link

@oliemansm : Thanks for the input and I did removed graphql-java-tools and tried it but still the same error :(

@oliemansm
Copy link
Member

Open a separate discussion for this to get further assistance.

@kumaritian
Copy link

@oliemansm : Thanks for your support. FYI : I have created a new issue #856

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants