I am trying to change spring xml settings to pure code based setting.
So I read official documents and some posts from blogs.
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
- javax.servlet.ServletContext doc clearly state that it has method
addListener
>> http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html - have to use Spring
WebApplicationInitializer.onStartup(ServletContext)
to set basic setting via Java source code, not XML - Can not load
addListener
fromServletContext
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'
container.
? I put that into code since that line is where my problem occurs. Except that, it is pretty valid java. If you do not mind visit the link I provided on original post. AndRootConfig
is just another java file which has@Configuration
on class definition. thanks. – PharmaceuticsaddListener
method. However in code, it is impossible. It just error so can not even compile – PharmaceuticsServletContext
andContextLoaderListener
classes to make sure there is no conflicting dependency? – Tit