spring-cloud-starter-oauth2 and spring-boot-starter-webflux no server on start - spring-security-oauth2

I have a simple spring application that use
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
My other dependencies are:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
I'have created a dummy controller:
#RestController
public class Controller {
#GetMapping("/")
String get(){
return "HELLO";
}
}
When I start the app I have strange error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$Enable WebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
It's seems that I have a conflict with spring-webmvc and webflux.
I want to be reactive and webmvc do not play well with spring reactive based on what I've read, So I've exclude spring-web-starter, but then I have...
org.springframework.context.ApplicationContextException: Unable to start reactive web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'httpHandler' defined in class path resource [org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfiguration$AnnotationConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.http.server.reactive.HttpHandler]: Factory method 'httpHandler' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webHandler' defined in class path resource [org/springframework/boot/autoconfigure/web/reactive/WebFluxAnnotationAutoConfiguration$EnableWebFluxConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/reactive/WebFluxAnnotationAutoConfiguration$EnableWebFluxConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
What is needed to make spring oauth2 works with spring-webflux ?
for info I am using snapshot for everything.
Thanks in advance

This is not supported at the moment (neither is the reactive bits of Spring Security).

Related

Incorporating Redis/Spring Session into my application prevents me from deploying the app

I am trying to incorporate SpringSession into my existing (non-Spring boot) application. I have followed Baeldung, which seems to make the most sense:
https://www.baeldung.com/spring-session
Here is my Maven dependencies:
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
Here is the configuration code that I have created:
#Configuration
#EnableRedisHttpSession
public class SessionConfig{
#Bean
public JedisConnectionFactory jedisConnectionFactory() {
JedisConnectionFactory jedisConnectionFactory = new
JedisConnectionFactory();
jedisConnectionFactory.setHostName("localhost");
jedisConnectionFactory.setPort(6379);
jedisConnectionFactory.setDatabase(1);
return jedisConnectionFactory;
}
#Bean
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory());
return template;
}
}
And here is the Initializer class that extends the HttpSessionInitializer:
public class Initializer extends AbstractHttpSessionApplicationInitializer {
public Initializer() {
super(SessionConfig.class);
}
}
My understanding is that this creates a bean that effectively intercepts sessions and uses Redis to manage them rather that using the Java In Memory session management.
However. I'm unable to deploy the application and am getting the following error in mt catalina logs:
07-Aug-2018 11:13:24.241 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:262)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4751)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5215)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:629)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1839)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
What I derive from this is that the classes that I am now including (possibly in the AbstractHttpSessionApplicationInitializer) are trying to load an application context which is conflicting with the ContextLoaderListener that is already declared in my web.xml. But if I remove that Listener from the web.xml, then that doesn't allow my app to deploy also.
I'm also getting this exception in my tomcat logs, but not sure if it's related:
07-Aug-2018 11:14:57.652 INFO [ektorp-idle-connection-monitor-thread-1] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load [org.apache.http.pool.AbstractConnPool$4]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [org.apache.http.pool.AbstractConnPool$4]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1311)
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1299)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1158)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.apache.http.pool.AbstractConnPool.closeExpired(AbstractConnPool.java:558)
at org.apache.http.impl.conn.PoolingClientConnectionManager.closeExpiredConnections(PoolingClientConnectionManager.java:302)
at org.ektorp.http.IdleConnectionMonitor$CleanupTask.run(IdleConnectionMonitor.java:52)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Is there anything that I am missing that could cause this error?
If you're using web.xml to bootstrap you web app, then you shouldn't be using AbstractHttpSessionApplicationInitializer but rather traditional XML configuration based approach.
You can take a look at Redis HttpSession with XML config guide that's available from Spring Session's reference documentation.
Your Spring config should contain the

Spring web application - Migration from tomcat to wildfly

I have a spring web application that uses Tomcat.I am trying to migrate it to jBoss/Wildfly application server. When trying to deploy it, I get these errors:
Cannot upload deployment: {"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./revomon-tracking-web-html" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./revomon-tracking-web-html: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'trackAlarmDao' defined in VFS resource [\"/content/revomon-tracking-web-html.war/WEB-INF/lib/revomon-tracking-orm-1.1.0-SNAPSHOT.jar/com/revomon/orm/core/tracking/dao/TrackAlarmDao.class\"]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: Error creating bean with name 'sessionFactory' defined in VFS resource [\"/content/revomon-tracking-web-html.war/WEB-INF/classes/context/application-context-repository.xml\"]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc/revomon_tracking -- service jboss.naming.context.java.jdbc.revomon_tracking; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in VFS resource [\"/content/revomon-tracking-web-html.war/WEB-INF/classes/context/application-context-repository.xml\"]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc/revomon_tracking -- service jboss.naming.context.java.jdbc.revomon_tracking Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc/revomon_tracking -- service jboss.naming.context.java.jdbc.revomon_tracking Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourcePosition': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc/tracking_position -- service jboss.naming.context.java.jdbc.tracking_position Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'trackAlarmDao' defined in VFS resource [\"/content/revomon-tracking-web-html.war/WEB-INF/lib/revomon-tracking-orm-1.1.0-SNAPSHOT.jar/com/revomon/orm/core/tracking/dao/TrackAlarmDao.class\"]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: Error creating bean with name 'sessionFactory' defined in VFS resource [\"/content/revomon-tracking-web-html.war/WEB-INF/classes/context/application-context-repository.xml\"]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc/revomon_tracking -- service jboss.naming.context.java.jdbc.revomon_tracking; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in VFS resource [\"/content/revomon-tracking-web-html.war/WEB-INF/classes/context/application-context-repository.xml\"]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc/revomon_tracking -- service jboss.naming.context.java.jdbc.revomon_tracking Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc/revomon_tracking -- service jboss.naming.context.java.jdbc.revomon_tracking Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourcePosition': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc/tracking_position -- service jboss.naming.context.java.jdbc.tracking_position Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in VFS resource [\"/content/revomon-tracking-web-html.war/WEB-INF/classes/context/application-context-repository.xml\"]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc/revomon_tracking -- service jboss.naming.context.java.jdbc.revomon_tracking Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc/revomon_tracking -- service jboss.naming.context.java.jdbc.revomon_tracking Caused by: javax.naming.NameNotFoundException: jdbc/revomon_tracking -- service jboss.naming.context.java.jdbc.revomon_tracking"},"WFLYCTL0412: Required services that are not installed:" => ["jboss.undertow.deployment.default-server.default-host./revomon-tracking-web-html"],"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined}
Please any suggestions how to fix it?

Spring Integration gateway error channel - no such bean exception

I've configured a spring integration gateway with a service activator backed by a threadpool.
Everything works fine, till I try to add my own error channel.
Spring begins to complain that it cannot find a bean by the name of the error channel.
Here is my xml config:
<int:gateway service-interface="Messaging.SendMessageToDeviceGateWay"
error-channel="send_message_to_device_error_channel"
default-request-channel="send_message_to_device_channel"
id="send_message_to_device_gateway">
</int:gateway>
<int:channel id="send_message_to_device_channel">
<int:queue message-store="redisMessageStore" />
</int:channel>
<bean id="sendMessageToDeviceServiceBeanId" class="Messaging.SendMessageToDeviceService" />
<int:service-activator input-channel="send_message_to_device_channel"
ref="sendMessageToDeviceServiceBeanId" method="send_message">
<int:poller fixed-rate="500" time-unit="MILLISECONDS"
task-executor="send_message_to_device_task_executor" receive-timeout="0" />
</int:service-activator>
<bean id="sendMessageToDeviceErrorHandlerBeanId"
class="Messaging.SendMessageToDeviceErrorHandler" />
<int:service-activator input-channel = "send_message_to_device_error_channel"
ref="sendMessageToDeviceErrorHandlerBeanId" method="handle_error">
</int:service-activator>
The error I am seeing is :
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'send_message_to_device_gateway': Cannot resolve reference to bean 'send_message_to_device_error_channel' while setting bean property 'errorChannel'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'send_message_to_device_error_channel' is defined
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1469)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1127)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 24 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'send_message_to_device_error_channel' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:694)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1168)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 37 more
Why is it looking for a bean by that name?
Thanks in advance,
Richard.
That's correct: any bean must be presented in the application context.
Even if you use a default errorChannel, it is populated to the application context by the Spring Integration infrastructure.
So, you must provide <channel id="send_message_to_device_error_channel"/> anyway.

Getting error while executing program in Eclipse IDE

Getting error while executing program in Eclipse:
og4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
May 21, 2014 5:23:24 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.gagan.crud.dao.BookDaoImpl] for bean with name 'bookDao' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.gagan.crud.dao.BookDaoImpl
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.gagan.crud.dao.BookDaoImpl] for bean with name 'bookDao' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.gagan.crud.dao.BookDaoImpl
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.gagan.crud.service.BookServiceImpl] for bean with name 'bookService' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.gagan.crud.service.BookServiceImpl
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
at

i have a problem with my project

i have a problem, i generated a build jar of other project, because i want to use its methods, then i imported this library in my project without never problem, well i used a MVC, in the controllerĀ“s name is java.java and it is here when i imported the new library and i used, then i run project, this is a error message,
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'urlMap' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'welcome' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Cannot resolve reference to bean 'catalogFacadeTarget' while setting bean property 'catalogFacadeImpl'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catalogFacadeTarget' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: jxl/read/biff/BiffException
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'welcome' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Cannot resolve reference to bean 'catalogFacadeTarget' while setting bean property 'catalogFacadeImpl'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catalogFacadeTarget' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: jxl/read/biff/BiffException
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catalogFacadeTarget' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: jxl/read/biff/BiffException
Caused by: java.lang.NoClassDefFoundError: jxl/read/biff/BiffException
It says, class jxl.read.biff.BiffException is not found. You need to add the jar file that contains jxl.read.biff.BiffException class to your projects classpath.
You can obtain the jar file from findjar.com

Resources