spring boot xml配置搭建 ssm 小案例(IDEA)
2021-01-27 04:14
标签:localhost ann work 容器 path class schema lte mvc 1、创建Maven工程,在pom.xml文件上添加 2、在resources文件下创建两个 .xml 配置文件,一个是对应 spring 的配置文件 applicationContext.xml ,另一个是对应 springmvc 的配置文件 spring-servlet.xml ; applicationContext.xml 配置文件中要配置开启包扫描,开启过滤器,但开启的包扫描设置成不扫描controller层; spring-servlet.xml 配置文件中要配置开启包扫描,不开启过滤器,但开启的包扫描只扫描controller层,并开启注解扫描; 3、构建web.xml 4、在 web.xml 中配置Filter、Listener、Servlet等 5、创建controller 6、创建service 7、配置tomcat 第一次配置时,需要选择图2中的 Configure... 选择 Tomcat 安装的位置 点击 Deployment 然后再点击右边的 “+” 然后再点击第一个,选择 war,最后OK 启动tomcat,访问http://localhost:8080/hello spring boot xml配置搭建 ssm 小案例(IDEA) 标签:localhost ann work 容器 path class schema lte mvc 原文地址:https://www.cnblogs.com/wdss/p/12849658.htmlxml version="1.0" encoding="UTF-8"?>
project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
modelVersion>4.0.0modelVersion>
groupId>org.javaboygroupId>
artifactId>xmlssmartifactId>
version>1.0-SNAPSHOTversion>
packaging>warpackaging>
dependencies>
dependency>
groupId>org.springframeworkgroupId>
artifactId>spring-webmvcartifactId>
version>5.1.6.RELEASEversion>
dependency>
dependencies>
project>
xml version="1.0" encoding="UTF-8"?>
beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
context:component-scan base-package="org.javaboy" use-default-filters="true">
context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
context:component-scan>
beans>
xml version="1.0" encoding="UTF-8"?>
beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
context:component-scan base-package="org.javaboy" use-default-filters="false">
context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
context:component-scan>
mvc:annotation-driven/>
beans>
xml version="1.0" encoding="UTF-8"?>
web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
context-param>
param-name>contextConfigLocationparam-name>
param-value>classpath:applicationContext.xmlparam-value>
context-param>
listener>
listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
listener>
servlet>
servlet-name>springmvcservlet-name>
servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
init-param>
param-name>contextConfigLocationparam-name>
param-value>classpath:spring-servlet.xmlparam-value>
init-param>
servlet>
servlet-mapping>
servlet-name>springmvcservlet-name>
url-pattern>/url-pattern>
servlet-mapping>
web-app>
@RestController
public class HelloController {
@Autowired
HelloService helloService;
@GetMapping(value = "/hello",produces = "text/html;charset=utf-8")
public String hello(){
return helloService.hello();
}
}
@Service
public class HelloService {
public String hello() {
return "爪洼男孩";
}
}
上一篇:关于JAVA中的JMM内存模型
下一篇:c语言标准io库
文章标题:spring boot xml配置搭建 ssm 小案例(IDEA)
文章链接:http://soscw.com/index.php/essay/47587.html