No bean named 'cxf' is defined - spring

I am trying to setup a simple restful web application, using tomcat 6.0.32, cxf 2.4.1. Anytime I issue any call, I get back an exception "No bean named 'cxf' is defined", where cxf is my bus.
Looking at the application log, I can see the cxf instance is created, and cached.
================ APP LOG BEGIN======================
910 DEBUG - Creating shared instance of singleton bean 'cxf'
910 DEBUG - Creating instance of bean 'cxf'
1018 DEBUG - Eagerly caching bean 'cxf' to allow for resolving potential circular references
1031 DEBUG - Returning eagerly cached instance of singleton bean 'cxf' that is not fully initialized yet - a consequence of a circular reference
1034 DEBUG - Finished creating instance of bean 'cxf'
1035 DEBUG - Returning cached instance of singleton bean 'org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor'
1035 DEBUG - Returning cached instance of singleton bean 'org.apache.cxf.bus.spring.Jsr250BeanPostProcessor'
1035 DEBUG - Returning cached instance of singleton bean 'org.apache.cxf.bus.spring.BusExtensionPostProcessor'
1035 DEBUG - Creating shared instance of singleton bean 'connection'
1035 DEBUG - Creating instance of bean 'connection'
1035 DEBUG - Eagerly caching bean 'connection' to allow for resolving potential circular references
1052 DEBUG - Finished creating instance of bean 'connection'
1052 DEBUG - Creating shared instance of singleton bean 'connectionService'
1052 DEBUG - Creating instance of bean 'connectionService'
1053 DEBUG - Eagerly caching bean 'connectionService' to allow for resolving potential circular references
1053 DEBUG - Returning cached instance of singleton bean 'connection'
1053 DEBUG - Returning cached instance of singleton bean 'cxf'
1121 DEBUG - Invoking init method 'create' on bean with name 'connectionService'
1356 DEBUG - Finished creating instance of bean 'connectionService'
1384 DEBUG fecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor#45d1c3cd]
1385 DEBUG - Returning cached instance of singleton bean 'lifecycleProcessor'
1387 DEBUG - Returning cached instance of singleton bean 'cxf'
1387 DEBUG - Returning cached instance of singleton bean 'cxf'
1388 DEBUG - Invoking init method 'create' on bean with name 'connectionService'
1391 DEBUG - Finished creating instance of bean 'connectionService'
1391 DEBUG - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor#2c3299f6]
1391 DEBUG - Returning cached instance of singleton bean 'lifecycleProcessor'
1391 DEBUG - Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
1391 INFO - Root WebApplicationContext: initialization completed in 1390 ms
================ APP LOG END======================
But when a request comes in, it always fails saying it can't find the bean.
===================== Tomcat (localhost) Log Begin ==================
INFO: Initializing Spring root WebApplicationContext
Jul 14, 2011 8:57:03 AM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cxf' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1079)
at org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:58)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:54)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:864)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1665)
at java.lang.Thread.run(Thread.java:662)
===================== Tomcat (localhost) Log End ==================
The only thing I can think of is that the bean is inserted in one context, and is being retrieved from another, but can't validate this or find a way around it. Any help would be greatly appreciated.

From your error log, I assume you use Spring, if so, you will need to add following lines to your Spring Context XML:
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-xml.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
Hope this helps.

If someone needs the Spring Java Based Configuration for solving this problem, there are two options:
You can import the cxf.xml file into your Java Config class with:
#ImportResource({ "classpath:META-INF/cxf/cxf.xml" })
Or you can define the bean programatically in your Java Configuration class with:
#Bean
public SpringBus cxf() {
return new SpringBus();
}
CXF + Spring Java Configuration class example.

In case anybody else gets here and is using mulesoft esb. The problem is also present in this system. To fix the issue, add the following section before the definition of the flows.
<spring:beans>
<spring:import resource="classpath:META-INF/cxf/cxf.xml" />
<spring:import resource="classpath:META-INF/cxf/cxf-extension-xml.xml" />
<spring:import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<spring:bean class="org.apache.cxf.bus.spring.Jsr250BeanPostProcessor" />
<spring:bean id="classname" name="classname" class="some.implemented.interface.path" />
</spring:beans>

Add these dependencies in the pom file:
<dependency>
   <groupId>org.apache.cxf</groupId>
   <artifactId>cxf-rt-rs-extension-search</artifactId>
   <version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-providers</artifactId>
<version>3.0.1</version>
</dependency>

Please check these steps in below:
1) lines mentioned in below should be included in your Spring Context XML:
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
2) Web.xml should be configured as below:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:cxf.xml</param-value>
</context-param>
3) Dependencies in below should be added inside your pom.xml:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-policy</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description</artifactId>
<version>${cxf.version}</version>
</dependency>
If all this didnt help you to solve your issue, the last step is to check your weblogic configuration, here are the steps you have to check on your weblogic server:
make sure you have define a machine to your server.
you need to specify your server and machine for your deployment as below:
Weblogic app deployment
I hope by checking all these steps your issue get solved.
Cheers

Related

Problem with Google Cloud Pub/Sub API and Spring boot application

I write spring boot application for subscribing Google cloud Pub/Sub topic for this I use Google's tutorial, but when I run application I have get this error
2019-02-02 18:03:10.248 INFO 15080 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-02-02 18:03:10.271 INFO 15080 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-02-02 18:03:10.610 ERROR 15080 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of method messageChannelAdapter in tech.garoon.cloud.CloudApplication required a bean of type 'org.springframework.cloud.gcp.pubsub.core.PubSubTemplate' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.cloud.gcp.pubsub.core.PubSubTemplate' in your configuration.
Process finished with exit code 1
How Can I solve this problem?
GcpPubSubAutoConfiguration provides autoconfiguration feature of creating necessary beans including PubSubTemplate. In your case, somethng is missed, Kindly ensure that dependencies are in place or recreate following bean to make it work.
#Bean
public PubSubTemplate pubSubTemplate(PubSubPublisherTemplate pubSubPublisherTemplate,
PubSubSubscriberTemplate pubSubSubscriberTemplate) {
return new PubSubTemplate(pubSubPublisherTemplate, pubSubSubscriberTemplate);
}
Additionally, make sure GcpContextAutoConfiguration is created based on below properties in application.properties.
spring.cloud.gcp.credentials.location=${gcp_credentials}
starter dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
</dependency>
Solution
I added this dependency
implementation 'org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.1.0.RELEASE'
My dependencies
dependencies {
implementation 'org.springframework.cloud:spring-cloud-gcp-pubsub:1.1.0.RELEASE'
implementation 'org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.1.0.RELEASE'
implementation "org.springframework.boot:spring-boot-starter-web:2.1.2.RELEASE"
implementation 'org.springframework.integration:spring-integration-core:5.1.2.RELEASE'
}
if using external configuration class that is registering your channels, message handlers etc, make sure to annotate the configuration class with #Import({GcpPubSubAutoConfiguration.class})
#Configuration
#Import({GcpPubSubAutoConfiguration.class})
public class PubSubConfig{
}
I ran into this issue with these versions of spring-boot and spring-cloud-gcp-starter-pub:
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
<version>1.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>1.2.8.RELEASE</version>
</dependency>
and in my application.properties I had
spring.cloud.gcp.pubsub.enabled=false for local development.
I removed spring.cloud.gcp.pubsub.enabled=false and it worked. Although now it creates a connection to the pubsub gcp topic, so for local development, you will need to comment out publishing, to avoid sending messages.

SpringRunner ignores application properties

I am trying to create Spring integration tests as follow:
#RunWith(SpringRunner::class)
#ActiveProfiles(profiles = ["Test"])
#ContextConfiguration(locations = ["classpath:**/applicationContext.xml"])
open class SimpleEntityIT {...}
applicationContact.xml contains:
<context:annotation-config/>
<context:spring-configured/>
<context:property-placeholder
ignore-resource-not-found="false"
location="classpath:application${spring.profiles.active}.properties,classpath:application.properties"/>
<context:component-scan base-package="net.goout"/>
The applicationContext is loaded, but it seems it is mostly ignored. Beans are not constructed via component-scan and the application.properties are completely ignored, no mention in logs:
2018-01-26 20:09:26,131 DEBUG Resolved location pattern [classpath:**/applicationContext.xml] to resources []
2018-01-26 20:09:26,132 DEBUG Loaded 0 bean definitions from location pattern [classpath:**/applicationContext.xml]
2018-01-26 20:09:26,167 INFO Refreshing org.springframework.context.support.GenericApplicationContext#aecb35a: startup date [Fri Jan 26 20:09:26 CET 2018]; root of context hierarchy
2018-01-26 20:09:26,167 DEBUG Bean factory for org.springframework.context.support.GenericApplicationContext#aecb35a: org.springframework.beans.factory.support.DefaultListableBeanFactory#20d3d15a: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory]; root of factory hierarchy
2018-01-26 20:09:26,198 DEBUG Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
2018-01-26 20:09:26,198 DEBUG Creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
2018-01-26 20:09:26,225 DEBUG Eagerly caching bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' to allow for resolving potential circular references
2018-01-26 20:09:26,231 DEBUG Finished creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
What am I not getting?
EDIT: Not event component-scan beans are not constructed, but really no beans are constructed – even those defined by <bean> in applicationContext.xml. It seems its content is just ignored even though it is correctly found.
As per the latest comments i believe this issue is solved, but even then couple of quick observations and alternatives :
a) You did not get an error on missing resource is because of below attr,i would suggest making it true to identify issues early on :
ignore-resource-not-found="false"
Also, you could use below :
#PropertySource(value = "xyz.properties", ignoreResourceNotFound = true)
b) Completely unrelated but :
#ActiveProfiles(profiles = ["Test"])
Could be written as :
#ActiveProfiles({"Test","QA"})
or in your application-test.properties
spring.profiles.active=Test,QA
c)For placing applicationContext.xml ,an alternative can also be placed in web.xml :
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/spring/*.xml</param-value>
</context-param>
(Although, annotation with specifying the exact location with #ContextConfiguration is completely fine as well! )
And above all , if you are using Annotation based configs, i would advice Spring boot :-)
Hope it helps!!
You should not copy applicationContext.xml to /test/resources yourself. Allow this to maven
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
</build>

"Application Failed to Start"

I am getting the following exception:
2017-05-24 09:41:40.779 INFO 4412 --- [ main] com.develop.NewApplication : Starting NewApplication on DESKTOP-4GP5JJA with PID 4412 (started by Athira S in C:\Users\Athira S\workspace\new)
2017-05-24 09:41:40.779 INFO 4412 --- [ main] com.develop.NewApplication : No active profile set, falling back to default profiles: default
2017-05-24 09:41:40.857 INFO 4412 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#6a28ffa4: startup date [Wed May 24 09:41:40 EDT 2017]; root of context hierarchy
2017-05-24 09:41:41.886 INFO 4412 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-05-24 09:41:42.198 WARN 4412 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
2017-05-24 09:41:42.214 INFO 4412 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-05-24 09:41:42.214 ERROR 4412 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
Assuming you are dealing with a spring boot application, you have 2 solutions:
OPTION 1. If you have a database you can hook up to your application, set the properties group for the spring datasource:
sample application.properties:
spring.datasource.url=jdbc://mysql://localhost:3306/dbname
spring.datasource.username=db_username
spring.datasource.password=db_password
(The same properties group can be set in yml if you are using that:)
sample application.yml:
spring:
datasource:
url: jdbc:mysql://localhost:3306/dbname
username: db_username
password: db_password
OPTION 2. If you don't have a database to connect to
Remove the dependency on spring-boot-starter-jdbc [or spring-boot-starter-jpa as the jdbc starter is a dependency of the starter jpa]
If you are using maven, that dependency looks like this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
In gradle, it'd be something like this:
compile 'org.springframework.boot:spring-boot-starter-jdbc'
If this isn't the case for you, please add some more context (such as your pom.xml | build.gradle, and/or application.properties | application.yml so that we can see more of what's going on.
I can not find your question. For this error, you should had some kind of embeded jdbc driver jar, like H2, sqlite, added in your pom. For H2 it is:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
You don't need version, if you use spring-boot-starter-parent as parent.
I was getting this because my port(8080) was being used in the background. killing that PID did the trick for me

Spring Cloud Config + Spring Cloud Bus + RabbitMQ - Not auto refreshing clients with local Git repository

I have some applications getting its configuration from a Spring Cloud Config Server (Brixton.RELEASE) and would like to enable the auto refresh of its properties. I have followed Spring Cloud Config documentation to configure both the server and client apps but, when making changes on the local git files nothing happens.
the default configuration also detects filesystem changes in local git
repositories (the webhook is not used in that case but as soon as you
edit a config file a refresh will be broadcast).
Can anybody point out what could be wrong or where to debug in Spring Cloud's code to check it?
Spring cloud Server Config:
server:
port: 8888
info:
description: Spring Cloud Config Server
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: file:///C:/Users/myuser/git/config-dev/
Spring Cloud Server pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
Spring Cloud Config Startup logs:
o.s.i.monitor.IntegrationMBeanExporter : Registering MessageChannel springCloudBusInput
o.s.i.monitor.IntegrationMBeanExporter : Located managed bean 'org.springframework.integration:type=MessageChannel,name=springCloudBusInput': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=springCloudBusInput]
o.s.i.monitor.IntegrationMBeanExporter : Registering MessageChannel springCloudBusOutput
o.s.i.monitor.IntegrationMBeanExporter : Located managed bean 'org.springframework.integration:type=MessageChannel,name=springCloudBusOutput': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=springCloudBusOutput]
o.s.i.monitor.IntegrationMBeanExporter : Registering MessageChannel errorChannel
o.s.i.monitor.IntegrationMBeanExporter : Located managed bean 'org.springframework.integration:type=MessageChannel,name=errorChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=errorChannel]
o.s.i.monitor.IntegrationMBeanExporter : Registering MessageChannel nullChannel
o.s.i.monitor.IntegrationMBeanExporter : Located managed bean 'org.springframework.integration:type=MessageChannel,name=nullChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=nullChannel]
o.s.i.monitor.IntegrationMBeanExporter : Located managed bean 'org.springframework.integration:type=MessageHandler,name=errorLogger,bean=internal': registering with JMX server as MBean [org.springframework.integration:type=MessageHandler,name=errorLogger,bean=internal]
o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase -2147482648
o.s.c.s.binding.BindableProxyFactory : Binding outputs for :interface org.springframework.cloud.bus.SpringCloudBusClient
o.s.c.s.binding.BindableProxyFactory : Binding :interface org.springframework.cloud.bus.SpringCloudBusClient:springCloudBusOutput
s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#707ca986: startup date [Fri May 13 10:03:10 CEST 2016]; root of context hierarchy
trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$73faa1d3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
e.m.a.config.ConfigServerApplication : No active profile set, falling back to default profiles: default
s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#1ca610a0: startup date [Fri May 13 10:03:11 CEST 2016]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#294a6b8e
o.s.c.support.GenericApplicationContext : Refreshing org.springframework.context.support.GenericApplicationContext#6048e26a: startup date [Fri May 13 10:03:11 CEST 2016]; root of context hierarchy
e.m.a.config.ConfigServerApplication : Started ConfigServerApplication in 2.907 seconds (JVM running for 12.366)
o.s.a.r.c.CachingConnectionFactory : Created new connection: SimpleConnection#7bbcf6f0 [delegate=amqp://guest#127.0.0.1:5672/]
o.s.i.endpoint.EventDrivenConsumer : Adding {message-handler:outbound.springCloudBus} as a subscriber to the 'springCloudBusOutput' channel
o.s.integration.channel.DirectChannel : Channel 'config-server:8888.springCloudBusOutput' has 1 subscriber(s).
o.s.i.endpoint.EventDrivenConsumer : started outbound.springCloudBus
o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase -2147482648
o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
o.s.i.endpoint.EventDrivenConsumer : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
o.s.i.channel.PublishSubscribeChannel : Channel 'config-server:8888.errorChannel' has 1 subscriber(s).
o.s.i.endpoint.EventDrivenConsumer : started _org.springframework.integration.errorLogger
o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147482647
o.s.c.s.binding.BindableProxyFactory : Binding inputs for :interface org.springframework.cloud.bus.SpringCloudBusClient
o.s.c.s.binding.BindableProxyFactory : Binding :interface org.springframework.cloud.bus.SpringCloudBusClient:springCloudBusInput
o.s.c.s.b.r.RabbitMessageChannelBinder : declaring queue for inbound: springCloudBus.anonymous.t4cuHSE6RfKRYvPvrgfbUg, bound to: springCloudBus
o.s.integration.channel.DirectChannel : Channel 'springCloudBus.anonymous.t4cuHSE6RfKRYvPvrgfbUg.bridge' has 1 subscriber(s).
o.s.i.a.i.AmqpInboundChannelAdapter : started inbound.springCloudBus.anonymous.t4cuHSE6RfKRYvPvrgfbUg
Client App pom.xml:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
Client App config:
spring:
application:
name: app
cloud:
config:
uri: http://localhost:8888
Client App Startup log:
o.s.b.a.e.m.EndpointHandlerMapping INFO - Mapped "{[/bus/refresh],methods=[POST]}" onto public void org.springframework.cloud.bus.endpoint.RefreshBusEndpoint.refresh(java.lang.String)
...
o.s.i.m.IntegrationMBeanExporter INFO - Registering beans for JMX exposure on startup
o.s.i.m.IntegrationMBeanExporter INFO - Registering MessageChannel springCloudBusInput
o.s.i.m.IntegrationMBeanExporter INFO - Located managed bean 'org.springframework.integration:type=MessageChannel,name=springCloudBusInput': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=springCloudBusInput]
o.s.i.m.IntegrationMBeanExporter INFO - Registering MessageChannel springCloudBusOutput
o.s.i.m.IntegrationMBeanExporter INFO - Located managed bean 'org.springframework.integration:type=MessageChannel,name=springCloudBusOutput': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=springCloudBusOutput]
o.s.i.m.IntegrationMBeanExporter INFO - Registering MessageChannel nullChannel
o.s.i.m.IntegrationMBeanExporter INFO - Located managed bean 'org.springframework.integration:type=MessageChannel,name=nullChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=nullChannel]
o.s.i.m.IntegrationMBeanExporter INFO - Registering MessageChannel errorChannel
o.s.i.m.IntegrationMBeanExporter INFO - Located managed bean 'org.springframework.integration:type=MessageChannel,name=errorChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=errorChannel]
o.s.i.m.IntegrationMBeanExporter INFO - Located managed bean 'org.springframework.integration:type=MessageHandler,name=org.springframework.cloud.bus.BusAutoConfiguration.acceptRemote.serviceActivator,bean=endpoint': registering with JMX server as MBean [org.springframework.integration:type=MessageHandler,name=org.springframework.cloud.bus.BusAutoConfiguration.acceptRemote.serviceActivator,bean=endpoint]
o.s.i.m.IntegrationMBeanExporter INFO - Located managed bean 'org.springframework.integration:type=MessageHandler,name=errorLogger,bean=internal': registering with JMX server as MBean [org.springframework.integration:type=MessageHandler,name=errorLogger,bean=internal]
o.s.b.a.e.j.EndpointMBeanExporter INFO - Registering beans for JMX exposure on startup
Try to go through this documentation spring-cloud-config-push-notifications and do not forget to install ngrock. Also if you just need to refresh on git commit then you do not even need cloud-bus project just config should be enough. Hope this helps.
You would need a Config server with Spring Cloud Bus and RabbitMQ (or Kafka or Redis) support.
...
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
...
RabbitMQ with the following exchange:
name: springCloudBus
type: topic
durable: true
autoDelete: false
internal: false
The Config server would send data to the topic once it receives push events from any of Github, Bitbucket or GitLab, via a webhook to http://<config-server>/monitor
And a client application with Config and RabbitMQ libraries:
...
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
...
Subscribed to the previous exchange to receive messages with the properties that need to be refreshed.
More could be found in my blog at: http://tech.asimio.net/2017/02/02/Refreshable-Configuration-using-Spring-Cloud-Config-Server-Spring-Cloud-Bus-RabbitMQ-and-Git.html with a brief explanation of the configuration, logs and full source code for the Config server and client app.
You need have fallowing dependent in the pom.xml
compile('org.springframework.cloud:spring-cloud-stream-binder-rabbit') - Gradle
if you have hosed you rabbitmq in the another system you need to specify the host file in the application.properties
spring.rabbitmq.host: {{hostname}}

Application context being loaded twice - Spring Boot

I have a fairly simple setup. A maven project with 3 modules : core/webapp/model. I'm using Spring boot to gear up my application. In webapp, i have a simple class WebappConfig as follows:
#Configuration
#EnableAutoConfiguration
#ComponentScan(excludeFilters = #ComponentScan.Filter(Configuration.class))
public class WebappConfig {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(WebappConfig.class);
app.setAdditionalProfiles("dev");
app.run(args);
}
}
and few classes in core/model module. My container-application point is :
public class AbcdXml extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(WebappConfig.class);
}
}
And no web.xml! My model's pom has following spring boot related dependency :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Core's pom.xml :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
Now running WebappConfig via Run as -> Java application works perfectly but i need to deploy the project as a war on tomcat7. Webapp's packaging is war. There is no tomcat provided jar's in lib except tomcat-jdbc and tomcat-tuli jar(Shouldn't be an issue?).
When i deploy my abcd.war, applicationcontext is getting loaded twice and result in following error stracktrace :
2014-06-27 11:06:08.445 INFO 23467 --- [ost-startStop-1] o.a.c.c.C.[.[localhost].[/abcd] : Initializing Spring embedded WebApplicationContext
2014-06-27 11:06:08.446 INFO 23467 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 19046 ms
2014-06-27 11:06:21.308 INFO 23467 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2014-06-27 11:06:21.313 INFO 23467 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'errorPageFilter' to: [/*]
2014-06-27 11:06:21.314 INFO 23467 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2014-06-27 11:06:26.073 INFO 23467 --- [ost-startStop-1] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2014-06-27 11:06:26.127 INFO 23467 --- [ost-startStop-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2014-06-27 11:06:26.511 INFO 23467 --- [ost-startStop-1] org.hibernate.Version : HHH000412: Hibernate Core {4.3.1.Final}
2014-06-27 11:06:26.521 INFO 23467 --- [ost-startStop-1] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2014-06-27 11:06:26.527 INFO 23467 --- [ost-startStop-1] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
//some info messages from spring boot
2014-06-27 11:07:31.664 INFO 23467 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-06-27 11:07:33.095 INFO 23467 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-06-27 11:07:33.096 INFO 23467 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-06-27 11:07:36.080 INFO 23467 --- [ost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2014-06-27 11:08:49.583 INFO 23467 --- [ost-startStop-1] o.s.boot.SpringApplication : Started application in 183.152 seconds (JVM running for 210.258)
2014-06-27 11:12:29.229 ERROR 23467 --- [ost-startStop-1] o.a.c.c.C.[.[localhost].[/abcd] : 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:277)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4937)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:976)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1653)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
There is no web.xml as i mentioned earlier.
Few interesting things that i can't figure out why :
After exploding the war, tomcat somehow create a ROOT folder with default web.xml[Must be Spring boot misconfiguration. How can i correct it? Pointers please?]
Even if i return same 'application' SpringApplicationBuilder in AbcdXml.java, i am facing the same issue of applicationcontext being loaded twice.
Thanks for your help!
EDIT 1:
Content of web.xml that is generated in ROOT folder :
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd" version="2.5">
</web-app>
If your app includes jersey-spring3 and you don't take steps to disable, it will try to create an ApplicationContext for you (helpful, not). There is a way to switch it off (in a WebApplicationInitializer):
servletContext.setInitParameter("contextConfigLocation", "<NONE>");
Or just use this: https://github.com/dsyer/spring-boot-jersey (include as a dependency).
In my case - I was having the same problem - seeing the Spring splash screen twice - It was because I had 2 classes that extended SpringBootServletInitializer. One was called SpringBootWebApplication and the other ServletInitializer. I just removed the ServletInitializer and it worked OK. Don't know why there were 2 classes - maybe because I got inspired from 2 different examples to assemble what I needed.
In my case the culprit was using Spring Boot 1.3.0.M4, along with Jersey 2.21. When I downgraded Spring Boot to 1.2.6.RELEASE the issue is gone.
The only thing I had to do was to explicitly override the following properties, as I needed spring 4.2.0 for Hibernate 5 support, and jackson 2.6.2 for JSR310 (java8 java.time) support:
<spring.version>4.2.0.RELEASE</spring.version>
<jackson.version>2.6.2</jackson.version>
EDIT: As of spring-boot 1.3.0.RELEASE, this bug still exists. See github
My main problem was my spring context was being loaded twice. As I printed every class's class loader I found that my Application was running twice. (i.e. when I debug in intellij after pressing F9 I was again landing up on same line i.e.
ConfigurableApplicationContext applicationContext = SpringApplication.run(ConfigAssignServer.class, args);
My problem was in pom.xml. I removed below dependency from my pom and it worked.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
Please check for your dependencies. Hope it will help someone. Enjoy coding :)
I had the same issue
I have src>main>webapp>WEB-INF>web.xml has an entity to saying
<listener>
<listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
</listener>
This is loading my context second time.
Comment it out and it will load only once.
I'm using Spring Boot 2.5.5 and experiencing the same issue but without error (WebApplicationContext) is being loaded twice along with scheduler calls are triggered as well too.
After debugging my application & Server(Tomcat v9.0.53) settings, I, myself able to solve the issue by deleting the "ServletInitializer.java" class which comes part of Spring initialiser project.
Now, all the issues resolved like schedulers are called once on predefined time along with the context loading.
Hope this resolves the issue.
Seems that "extends SpringBootServletInitializer" not work well with #SpringBootApplication in tomcat but when run with maven no duplicated beans is initialized so removing "extends SpringBootServletInitializer" from application main class solve the problem
In the Spring framework, usually for loading something like a global or root context, you club all the bean/resources shared by multiple servlet contexts.
Or loading a specific servlet context. Mvc-dispatcher config file is used to load config file, so you don't need to explicitly define it.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
In your case, seems when you are running as a Java application, auto-detection of Mvc-dispatcher doesn't happen and you are able to execute the code successfully. Whereas when deployed it gets initiated both from root and mvc-dispatcher.
Use empty context: <context-param/>
I don’t see the contents of web.xml here, So I am throwing a quick suggestion from both perspectives.
Please try to delete dependency from the global/root context.
Or in case #EnableAutoConfiuguration is used, get rid of it.
#EnableAutoConfiuguration from the API says "Enable auto-configuration of the Spring Application Context, attempting to guess and configure beans that you are likely to need."
#ComponentScan would also instantiate the beans. IT will scan the packages, find and register the beans.
As you are using both these annotations, I guess that is why its loading twice.

Resources