I am trying to change spring xml settings to pure code based setting.
So I read official documents and some posts from blogs.
e.g. http://docs.spring.io/spring-framework/docs/4.1.x/javadoc-api/org/springframework/web/WebApplicationInitializer.html
An I made a code like ...
public class TestInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container)
throws ServletException {
// TODO Auto-generated method stub
System.out.println("on Startup method has called.");
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(RootConfig.class);
container.
//container.addListener(new ContextLoaderListener(ctx));
}
};
A problem here. In those pages, they use addListener(new ContextLoaderListener(ctx))
method to set context. However my eclipse can not find that method from container
variable.
I do not know any clue why my container variable(javax.servlet.ServletContext instance) can not read this method.
Thanks for your answer:D
P.S.
My spring version is 4.1.6.RELEASE
and I include servlet3.0, spring-context, spring-webmvc
on pom.xml
.
========================
Maybe I got some communication problem, So I summarize this :D
addListener
>>
http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html
WebApplicationInitializer.onStartup(ServletContext)
to set basic setting via Java source code, not XMLaddListener
from ServletContext
class.=================================
Edit. This is not error on console. However it is the only message I got. It is from eclipse toolkit.
The method addListener(ContextLoaderListener) is undefined for the type ServletContext
than recommendation is Add cast to 'container'
To follow up on what @JuneyoungOh has commented, turns out that the problem is because of conflicting dependency. And these are the ways to solve this problem :
* make version 3.0.1 and artifactId 'javax.servlet-api' or
* add tomcat(in my case 7.0) to project build path and remove servlet dependency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With