Issue
I'm following the docs of spring framework and trying to realize it by code, but I'm stuck on AppConfig class. What dependency do I need to import AppConfig class? I've injected spring-beans, spring-web, spring-context, spring-webmvc already and my spring version is 5.2.5.RELEASE.
I googled "AppConfig cannot be resolved to a type" but couldn't get anything about it.
And this is the part of code from https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#spring-web
public class MyWebApplicationInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) {
// Load Spring web application configuration
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(AppConfig.class); // <-- this is the part I need AppConfig.
// Create and register the DispatcherServlet
DispatcherServlet servlet = new DispatcherServlet(context);
ServletRegistration.Dynamic registration = servletContext.addServlet("app", servlet);
registration.setLoadOnStartup(1);
registration.addMapping("/app/*");
}
}
Solution
You need to create the Configuration
bean first named AppConfig .
Some thing like below:
@Configuration
public class AppConfig {
@Bean(name="demoService")
public DemoClass service()
{
}
}
You can find plenty of exmaples on web. One Example - Here
Answered By - Tarun