因为配置-容器都从子容器WebApplicationContext启动

WebApplicationContext-属于springMVC容器

package com.jt.manage.controller;

import java.util.List;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.jt.manage.pojo.User;
import com.jt.manage.service.UserService;

@Controller
@RequestMapping("/")
public class UserController implements ApplicationContextAware{
    @Autowired
    private UserService userService;
    @RequestMapping("findAll")
    public String findUser(Model model){
        List userList=userService.findUserList();
        //将数据传递到页面中
        model.addAttribute("userList",userList);
        //将数据传递到页面中
        return "userList";
    }
    //看容器是什么容器
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("Controller:"+applicationContext);
    }
}
package com.jt.manage.service;

import java.util.List;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import com.jt.manage.mapper.UserMapper;
import com.jt.manage.pojo.User;
@Service
public class UserServiceImpl implements UserService,ApplicationContextAware {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List findUserList() {
        return userMapper.findUserList();
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("Service:"+applicationContext);
    }
}
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building jt-manage Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ jt-manage >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ jt-manage ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 6 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ jt-manage ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) < process-classes @ jt-manage <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ jt-manage ---
[INFO] Running war on http://localhost:8091/
[INFO] Using existing Tomcat server configuration at D:\jtwork\jt-manage\target\tomcat
[INFO] create webapp with contextPath: 
九月 30, 2018 9:24:22 上午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8091"]
九月 30, 2018 9:24:22 上午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Tomcat
九月 30, 2018 9:24:22 上午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.47
九月 30, 2018 9:24:25 上午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
九月 30, 2018 9:24:25 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring FrameworkServlet 'DispatcherServlet'
Service:WebApplicationContext for namespace 'DispatcherServlet-servlet': startup date [Sun Sep 30 09:24:25 CST 2018]; root of context hierarchy
Controller:WebApplicationContext for namespace 'DispatcherServlet-servlet': startup date [Sun Sep 30 09:24:25 CST 2018]; root of context hierarchy
九月 30, 2018 9:24:28 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8091"]

你可能感兴趣的:(因为配置-容器都从子容器WebApplicationContext启动)