我的豆是:
@Component
public class KidsServerStartUp implements ServletContextListener
{
UploadService uplService;
@Autowired
public void setUplService( UploadService uplService )
{
this.uplService = uplService;
}
public void contextInitialized(ServletContextEvent event) {
System.out.println ( uplService );
}
}
在 web.xml 中;我首先调用spring框架来设置所有bean;然后设置启动监听器:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.kids.util.KidsServerStartUp</listener-class>
</listener>
uplService 被打印为 null !