java.lang.NoClassDefFoundError: org/springframework/messaging/converter/MessageConverter - spring

I am new to Spring Integration . I am not using maven and my integration-spring.xml is located inside src/resources/integration-spring.xml and all my jars are having v4.0.5+. I am getting below exception when running my JUnit Test case.
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:331)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:213)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:290)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [resources/integration-spring.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/messaging/converter/MessageConverter
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:414)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
integration-spring.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
<int:gateway service-interface="com.fil.MyService" id="myGateway"
default-request-channel="in" />
<int:service-activator input-channel="in" method="someMethod"
ref="exampleHandler" />
<bean id="exampleHandler" class="com.fil.MyServiceImpl" />
Test.java
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import com.fil.MyService;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = { "/resources/integration-spring.xml" })
public class MyServiceTest {
#Autowired
private MyService service;
#Test
public void test() {
try{
service.single("hELLO ");
}
catch(Exception e){
e.printStackTrace();
}
}
}

This problem may occur, when you use not compatible spring boot and spring libraries too.
I my case I had to to update spring boot to current version.

You really should use maven or gradle to manage your project's dependencies; doing it manually is just too painful - especially with regard to getting all the versions right.
NoClassDefFoundError: org/springframework/messaging/converter/MessageConverter
The org.springframework.messaging package is provided by the spring-messaging jar file from the core Spring Framework. It contains general messaging abstractions used by Spring Integration (and other Spring projects).
Since you are "new" to the framework(s), you really should be using the latest versions:
org.springframework.integration:spring-integration-core:4.3.9.RELEASE
which depends on
org.springframework:spring-messaging:4.3.8.RELEASE
by default.
v4.0.5+
You must make sure that all jars from the same project (Spring Integration or Spring Framework) have their same respective versions (spring-beans, spring-messaging, etc must match and spring-integration-* must all be the same version).

Related

Spring 4.x based CXF web service configuration - WildFly 10.1

We would like to migrate our Spring application from JBoss 7.1.1 to WildFly 10.1. We used CXF based and Spring managed web services but on WildFly 10.1 we couldn't configure these services.
We tried two methods.
When we use WildFly webservices subsystem the web services are published correctly but in WS implementation we can't access spring managed beans.
When we exclude webservices subsystem in the jboss-deployment-structure.xml, configure CXFServlet in web.xml and configure jaxws:endpoint in spring xml configuration file the log shows that service creation is ok, but not based on the real implementation. Wrong service name, namespace and address.
Used spring configuration:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="testWs" implementor="ns.test.ws.impl.TestWsImpl"
address="/test">
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
</jaxws:properties>
</jaxws:endpoint>
</beans>
Log content:
18:31:11,783 INFO
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
(ServerService Thread Pool -- 58) Loading XML bean definitions from
class path resource [META-INF/cxf-beans.xml] 18:31:12,177 INFO
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
(ServerService Thread Pool -- 58) Loading XML bean definitions from
class path resource [META-INF/cxf/cxf.xml] 18:31:12,290 INFO
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
(ServerService Thread Pool -- 58) Loading XML bean definitions from
class path resource [META-INF/cxf/cxf-extension-jaxws.xml]
18:31:12,455 INFO
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
(ServerService Thread Pool -- 58) Loading XML bean definitions from
class path resource [META-INF/cxf/cxf-servlet.xml] 18:31:12,960
INFO
[org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean]
(ServerService Thread Pool -- 58) Creating Service
{http://impl.ws.test.ns/}TestWsImplService from class
ns.test.ws.impl.TestWsImpl
WS implementation:
package ns.test.ws.impl;
import java.util.ArrayList;
import javax.jws.WebService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import ns.test.ws.api.TestWs;
import ns.test.ws.domain.ApplicationInfo;
import ns.test.ws.domain.ApplicationInfoRequest;
import ns.test.ws.domain.ApplicationInfoResultContainer;
import ns.test.ws.domain.CallContext;
import ns.test.ws.domain.ResultContext;
import ns.test.ws.domain.ResultMessage;
#WebService(name = "ApplicationInfoService", serviceName = "ApplicationInfoService", portName = "ApplicationInfoServicePort", endpointInterface = "ns.test.ws.api.TestWs", targetNamespace = "http://test.ns/")
#Transactional
public class TestWsImpl implements TestWs {
#SuppressWarnings("unused")
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestWsImpl.class);
#Autowired
private VersionInfo versionInfo;
public ApplicationInfoResultContainer test(CallContext callContext, ApplicationInfoRequest appInfoRequest) {
ApplicationInfo result = new ApplicationInfo();
result.setAppName(versionInfo.getAppName());
result.setAppVersion(versionInfo.getVersion());
ResultContext resultContext = new ResultContext();
resultContext.setCorrelationId("corrId");
resultContext.setHighestMessageSeverity("W");
resultContext.setMessageList(new ArrayList<ResultMessage>());
resultContext.getMessageList().add(new ResultMessage("code", "sev", "system", "message"));
return new ApplicationInfoResultContainer(result, resultContext);
}
}
What do we wrong? How should we configure the spring application?
Used dependencies:
WildFly 10.1
CXF 3.1.6 (WildFly 10.1 module)
Spring 4.3.7
I found the solution. See my sample code on the following repo.
https://github.com/SeniorRoland/spring-wildfly

#PostConstruct spring does not get called without bean declaration

Why post construct does not get called without putting bean in applicationContext.xml
Here is my class which contains #PostConstruct annotation.
package org.stalwartz.config;
import javax.annotation.PostConstruct;
import javax.inject.Singleton;
#Singleton
public class PropertyLoader {
#PostConstruct
public void init() {
System.out.println("PropertyLoader.init()");
}
}
Below is my applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr/spring-dwr-3.0.xsd">
<dwr:annotation-config />
<dwr:annotation-scan base-package="org.stalwartz" scanDataTransferObject="true" scanRemoteProxy="true" />
<dwr:url-mapping />
<!-- <bean id="proeprtyLoader" class="org.stalwartz.config.PropertyLoader"></bean> -->
<dwr:controller id="dwrController" debug="false">
<dwr:config-param name="activeReverseAjaxEnabled" value="true" />
</dwr:controller>
<context:annotation-config>
<context:component-scan base-package="org.stalwartz" annotation-config="true"></context:component-scan>
</context:annotation-config>
<mvc:annotation-driven />
...
...
...
</beans>
Looks simple, but it does not work without uncommenting bean declaration.
In Spring environment initialization callback method (the one annotated by #PostConstruct) make sense only on spring-managed-beans. To make instance(s) of your PropertyLoader class managed, you must do one of the following:
Explicitly register your class in context configuration (as you did)
<bean id="proeprtyLoader" class="org.stalwartz.config.PropertyLoader"></bean>
Let component scanning do the work (as you nearly did), but classes must be annotated by one of #Component, #Repository, #Service, #Controller.
Note from Spring documentation: The use of <context:component-scan> implicitly enables the functionality of <context:annotation-config>. There is usually no need to include the <context:annotation-config> element when using <context:component-scan>.
Because putting bean in applicationContext.xml you are adding bean to Spring container, which has interceptor for this annotation. When Spring inject beans it checks #PostConstruct annotation, between others.
When you call simple new PropertyLoader() JVM will not search for the #PostConstruct annotation.
From doc of #PostConstruct annotation:
The PostConstruct annotation is used on a method that needs to be executed
after dependency injection is done to perform any initialization. This
method MUST be invoked before the class is put into service. This
annotation MUST be supported on all classes that support dependency
injection. The method annotated with PostConstruct MUST be invoked even
if the class does not request any resources to be injected.
Singleton is a scope annotation. It can be used to declare 'singletone' scope for a particular bean, but not instantiate it. See this article.
If you want to instantiate your class as singleton you can try Spring Service annotation.
#Service
public class PropertyLoader {
#PostConstruct
public void init() {
System.out.println("PropertyLoader.init()");
}
}
Also, you can replace annotation-config tag with component-scan. Here is a good article about differences of annotation-config and component-scan tags.
you are using #Singleton from javax.inject package which is not picked up as bean by spring container. Change it to :
package org.stalwartz.config;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
#Component
public class PropertyLoader {
#PostConstruct
public void init() {
System.out.println("PropertyLoader.init()");
}
}
and the spring will auto detect PropertyLoader and will include it in Spring container as bean via the #Component annotation and this bean will be with singleton scope
by default a bean is singleton scoped in Spring, and #PostConstruct is usually used for service beans and service beans must scoped prototype and here because you need multiple objects for that particular class, Spring will provide you singleton instance.
also by doing this spring will attempt multiple times to find this service bean and finally throws below exception:
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
so try like this in annotation way:
package org.stalwartz.config;
import javax.annotation.PostConstruct;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
#Component
#Scope("prototype") //you have to make it prototype explicitly
public class PropertyLoader {
#PostConstruct
public void init() {
System.out.println("PropertyLoader.init()");
}
}
Now every thing is good, and work fine for you.
add this dependency to pom.xml
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>

Spring Beginner - No such field error

I am new to spring. I am developing one sample project using spring. I am getting the following exception when I provide a value in Beans.xml. Please provide solution.
Beans.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="helloWorld" class="com.dhr.spring.beans.HelloWorld">
<property name="message" value="d" />
</bean>
</beans>
HelloWorld.java:
public class HelloWorld {
private String message;
public void setMessage(String message){
this.message = message;
}
public void getMessage(){
System.out.println("Your Message : " + message);
}
}
MainApp:
public class MainApp {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
obj.getMessage();
}
}
Exception:
Caused by: java.lang.NoSuchFieldError: NULL
at org.springframework.expression.TypedValue.<clinit>(TypedValue.java:31)
at org.springframework.expression.spel.support.StandardEvaluationContext.setRootObject(StandardEvaluationContext.java:85)
at org.springframework.expression.spel.support.StandardEvaluationContext.<init>(StandardEvaluationContext.java:74)
at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:124)
at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1299)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.evaluate(BeanDefinitionValueResolver.java:210)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:182)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
... 11 more
Welcome! To the ambiguous world of Spring! Where stack traces are long and documentation is short convoluted.
I have seen this error several times and, at least for me, it usually has to do with dependency inconsistencies.
I see that you just posted you are not using Maven. I can almost assure you that that is the problem. You really SHOULD be using Maven. The amount of work it will save you is monumental.
Edit: To make this post more answer-like: You are getting the error due to dependency inconsistencies. You are manually putting Spring JAR files into your dependency tree which is not recommended.
Either 1) Use Maven to handle dependency management (recommended) or 2) Ensure that all your JAR files utilize non-conflicting and coherent dependency trees.
For instance, you are using org.springframework.expression-3.0.3.RELEASE which is not part of the 3.1.x group. So, replace the jar file with org.springframework.expression-3.1.0-RELEASE

Spring 3.1 Missing ServletContext

I am trying to write an integration test for my spring application. All my spring beans are defined in an xml file, so I am using profiles to parse them out.
Here is my test:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(loader = GenericXmlContextLoader.class, locations = {"classpath:/spring/spring-config.xml"})
#Profile("dev")
public class AccountDAOTest {
private EmbeddedDatabase database;
#Autowired
AccountDAO accountDAO;
#Before
public void setUp() {
System.setProperty("spring.profiles.active", "dev");
database = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL).setName("memdb")
.addScript("classpath:resources/createAccount.sql").build();
Assert.assertNotNull(database);
}
#Test
public void testFind() throws Exception {
List<Account> accounts = accountDAO.findAll();
}
}
My spring-config.xml is just a standard configuration file
<beans>
<beans profile="prod" >
<context:annotation-config/>
<tx:annotation-driven transaction-manager="myTX" proxy-target-class="true"/>
<aop:aspectj-autoproxy/>
...
<beans profile="prod" >
<transaction managers, httprequests and such >
</beans>
<!-- end of production beans -->
<!-- the following are for local testing -->
<beans profile="dev" >
</beans>
<transaction managers and such >
<!-- end of local testing beans -->
</beans>
My spring version is 3.1.Release for spring-test, spring-transaction, spring.web.servlet, spring.web
As I am using servlet 2.5 I cannot use the newer Spring MVC configuration
When I try and run my test I get the following exception:
Caused by:
org.springframework.beans.factory.BeanDefinitionStoreException:
Factory method [public org.springframework.web.servlet.HandlerMapping
org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.defaultServletHandlerMapping()]
threw exception; nested exception is
java.lang.IllegalArgumentException: A ServletContext is required to
configure default servlet handling
Caused by: java.lang.IllegalArgumentException: A ServletContext is
required to configure default servlet handling
I can't figure out:
Why the servlet is required when I don't use it explicitly for tests
How to get the test servlet context loaded for xml without using spring mvc
Split the spring context config into root (non-web-related beans) and mvc (web-related beans) parts, or create a separate test config xml.

Spring #Scheduled is executing task twice when using annotations

I have made task using Spring #Scheduled annotation, but for some reason it is executing task twice. My Spring Framework version is 3.0.2.
#Service
public class ReportService {
#Scheduled(fixedDelay=1000 * 60 * 60* 24)
#Transactional
public void dailyReportTask()
{
... code here ...
}
}
Here is my XML:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<task:scheduler id="taskScheduler" />
<task:executor id="taskExecutor" pool-size="1" />
<task:annotation-driven executor="taskExecutor"
scheduler="taskScheduler" />
</beans>
it is happening because of context listener
Just remove
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
from web.xml it should work.
I had this same problem, and I eventually found out that the problem was occurring as a result of the beans being created in the root context as well as the servlet context.
So, to fix this, you need to separate the creation of the beans into the appropriate contexts.
This answer explains really well how to that and was what fixed my problem.
According to this post: http://www.vodori.com/blog/spring3scheduler.html
Spring 3.0.0 Release had a bug where
web apps with a task scheduler would
end up executing scheduled methods
twice. This has been resolved in
Spring 3.0.1.
There has been another bug reported which affects Version/s: 3.0.2
https://jira.springsource.org/browse/SPR-7216
Which should be fixed in Version/s: 3.0.3.
I just had this problem recently and it was caused by my app being deployed twice in Tomcat by eclipse. The problem was that I had renamed my application in eclipse but the "wb-module deploy-name" specified in the "org.eclipse.wst.common.component" .settings file still had the old name.
In the tomcat manager, I could see that I had 2 apps running with different names.
Where are you actually running it? Your PC? Single server? 2 x load-balanced app servers?
Could be it's running on (a) your PC and (b) your server, so it just looks like it's running twice, if you see what I mean: it's correctly running once, just on two distinct locations.
Check if you have any manual scheduler config in your configuration files (through Java/XML). I'ved the same problem, and I discover that my config was loading my scheduler class twice:
In Java:
package com.mywork.br.myschuedulerpackage;
{...}
#Configuration
#EnableScheduling
public class SchedulerConfiguration {
#Bean
public CTXDataImporterScheduler ctxDataImporterScheduler() {
return new CTXDataImporterScheduler();
}
}
In XML applicationContext.xml:
<context:component-scan base-package="com.mywork.br.myschuedulerpackage" />
And in my scheduler class, I had #Component annotation thats was catch by the component scan and loaded a second time causing the #scheduler methods being executed twice.
I removed the Java config and then is working well now!
To solve twice-working of #Scheduled method just delete ContextLoaderListener from you web.xml (if you use web.xml-based application):
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Or if you use WebApplicationInitializer-based application just delete a string that adds ContextLoaderListener:
package com.dropbox.shortener.config;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.DispatcherServlet;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
public class DropboxShortenerWebApplicationInitializer implements WebApplicationInitializer {
#Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(AppConfig.class);
// (!) Delete the next string
// container.addListener(new ContextLoaderListener(rootContext));
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(WebConfig.class);
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
setupCharEncodingFilter(container);
}
private void setupCharEncodingFilter(ServletContext container) {
container.setInitParameter("defaultHtmlEscape", "true");
FilterRegistration charEncodingFilterReg = container.addFilter("CharacterEncodingFilter", CharacterEncodingFilter.class);
charEncodingFilterReg.setInitParameter("encoding", "UTF-8");
charEncodingFilterReg.setInitParameter("forceEncoding", "true");
charEncodingFilterReg.addMappingForUrlPatterns(null, false, "/*");
}
}
Use #Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE) on your bean
Disabling below will work.
<!-- <listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener> -->
One solution I would suggest is to do component scat like this
-In application context
<context:component-scan base-package="com.abc.cde.dao" />
In yourservlet-servlet.xml
<!-- package that had all the #Controller classes -->
I this way the servlet is only loaded if the web.xml is loaded
Similar can be done for task

Resources