以下是汇总代码-
web.xml
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
调度程序-servlet.xml
<context:component-scan base-package="controller"/>
<bean id="myservice1" class="service.MyServiceImpl1"></bean>
<bean id="myservice2" class="service.MyServiceImpl2"></bean>
<bean id="mydao" class="dao.MyDaoImpl"></bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
并在控制器类中引用它们-
@Controller
public class MyController {
@Autowired
MyService myServiceImpl2;
}
现在myServiceImpl2
将引用 bean 对象。