Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Kotlin
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Paul Clapham
Devaka Cooray
Tim Cooke
Sheriffs:
Rob Spoor
Liutauras Vilda
paul wheaton
Saloon Keepers:
Tim Holloway
Tim Moores
Mikalai Zaikin
Carey Brown
Piet Souris
Bartenders:
Stephan van Hulst
Forum:
Kotlin
Why?
Pieter Jansens
Ranch Hand
Posts: 56
1
posted 10 months ago
Number of slices to send:
Optional 'thank-you' note:
Send
This class works fine:
@Controller class UserController( private val userService: UserService) { @MutationMapping fun register(@Argument input: User): User { return userService.save(input) } @QueryMapping fun userByUsername(@Argument username: String): User { return userService.findByUsername(username) } // @PreAuthorize("hasRole('ADMIN')") @QueryMapping fun allUsers():List<User>{ return userService.findAll() } }
But once I uncomment the PreAUthorize annotation ithe program dosn't compile anymore.
Could not generate CGLIB subclass of class com.onestopcoding.forum.resolvers.UserController: Common causes of this problem include using a final class or a non-visible class
When i mark de controllerClass as open, it compiles, but when executing the methods my userservice isn't autowired.... Any ideas?
Tim Moores
Saloon Keeper
Posts: 7643
178
posted 10 months ago
Number of slices to send:
Optional 'thank-you' note:
Send
Is
PreAuthorize
being imported, and is it in the compile-time classpath?
Pieter Jansens
Ranch Hand
Posts: 56
1
posted 10 months ago
Number of slices to send:
Optional 'thank-you' note:
Send
If it wouldn't be, intellij would tell me so, but yes it is
Pieter Jansens
Ranch Hand
Posts: 56
1
posted 10 months ago
Number of slices to send:
Optional 'thank-you' note:
Send
This is the full stacktrace:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController' defined in file [D:\OneStopCoding\projecten\forum\target\classes\com\onestopcoding\forum\resolvers\UserController.class]: Could not generate CGLIB subclass of class com.onestopcoding.forum.resolvers.UserController: Common causes of this problem include using a final class or a non-visible class at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:608) ~[spring-beans-6.1.1.jar:6.1.1] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-6.1.1.jar:6.1.1] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325) ~[spring-beans-6.1.1.jar:6.1.1] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.1.jar:6.1.1] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) ~[spring-beans-6.1.1.jar:6.1.1] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.1.1.jar:6.1.1] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) ~[spring-beans-6.1.1.jar:6.1.1] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:946) ~[spring-context-6.1.1.jar:6.1.1] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:616) ~[spring-context-6.1.1.jar:6.1.1] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.0.jar:3.2.0] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:753) ~[spring-boot-3.2.0.jar:3.2.0] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:455) ~[spring-boot-3.2.0.jar:3.2.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:323) ~[spring-boot-3.2.0.jar:3.2.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1342) ~[spring-boot-3.2.0.jar:3.2.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1331) ~[spring-boot-3.2.0.jar:3.2.0] at com.onestopcoding.forum.ForumApplication.main(ForumApplication.java:16) ~[classes/:na] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:578) ~[na:na] at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.2.0.jar:3.2.0] Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class com.onestopcoding.forum.resolvers.UserController: Common causes of this problem include using a final class or a non-visible class at org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:227) ~[spring-aop-6.1.1.jar:6.1.1] at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:160) ~[spring-aop-6.1.1.jar:6.1.1] at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110) ~[spring-aop-6.1.1.jar:6.1.1] at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.buildProxy(AbstractAutoProxyCreator.java:517) ~[spring-aop-6.1.1.jar:6.1.1] at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:464) ~[spring-aop-6.1.1.jar:6.1.1] at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:369) ~[spring-aop-6.1.1.jar:6.1.1] at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:318) ~[spring-aop-6.1.1.jar:6.1.1] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:437) ~[spring-beans-6.1.1.jar:6.1.1] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-6.1.1.jar:6.1.1] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601) ~[spring-beans-6.1.1.jar:6.1.1] ... 18 common frames omitted Caused by: java.lang.IllegalArgumentException: Cannot subclass final class com.onestopcoding.forum.resolvers.UserController at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:653) ~[spring-core-6.1.1.jar:6.1.1] at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:26) ~[spring-core-6.1.1.jar:6.1.1] at org.springframework.cglib.core.ClassLoaderAwareGeneratorStrategy.generate(ClassLoaderAwareGeneratorStrategy.java:57) ~[spring-core-6.1.1.jar:6.1.1] at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:366) ~[spring-core-6.1.1.jar:6.1.1] at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:575) ~[spring-core-6.1.1.jar:6.1.1] at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:127) ~[spring-core-6.1.1.jar:6.1.1] at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:317) ~[spring-core-6.1.1.jar:6.1.1] at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:562) ~[spring-core-6.1.1.jar:6.1.1] at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:407) ~[spring-core-6.1.1.jar:6.1.1] at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:62) ~[spring-aop-6.1.1.jar:6.1.1] at org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:218) ~[spring-aop-6.1.1.jar:6.1.1] ... 27 common frames omitted Process finished with exit code 1
Stephan van Hulst
Bartender
Posts: 15720
367
posted 10 months ago
Number of slices to send:
Optional 'thank-you' note:
Send
The error message is pretty self-explanatory: Your
UserController
class is final.
Spring tries to generate a proxy of your
UserController
class by making a subclass of it. It can't do this if the class is final.
Since you're using Kotlin, the class is final by default. You have to make it non-final by using the
open
keyword.
Pieter Jansens
Ranch Hand
Posts: 56
1
posted 10 months ago
Number of slices to send:
Optional 'thank-you' note:
Send
As I stated in the original question, once I mark the class as open, it compiles, but my service isn't autowired
Stephan van Hulst
Bartender
Posts: 15720
367
posted 10 months ago
Number of slices to send:
Optional 'thank-you' note:
Send
What makes you think it isn't autowired?
Do you manually instantiate the
UserController
class and call its methods?
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Graphql: Springsecurity
spring @PreAuthorize not working with @EnableGlobalMethodSecurity(prePostEnabled = true)
Problem with SpringBoot in Eclipse
Error: Bean property 'userDAO' is not writable or has an invalid setter method.
Spring Role Hierarchy: NullPointerException
More...