无配置文件实现简单web工程
来源:互联网 发布:淘宝耐克双肩包 编辑:程序博客网 时间:2024/05/10 19:58
spring-mvc.xml文件之Java配置类
package com.csl.demo.annotation;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.EnableWebMvc;import org.springframework.web.servlet.view.InternalResourceViewResolver;import org.springframework.web.servlet.view.JstlView;/** * * @author Cherry * @date 2017年10月3日 */@Configuration@EnableWebMvc//启用WebMvc@ComponentScan("com.csl.demo.annotation")public class SpringCongfigs { //注入视图资源解析器 @Bean("viewResolver") public InternalResourceViewResolver viewResolver(){ //创建 InternalResourceViewResolver irv = new InternalResourceViewResolver(); //设置前后缀// irv.setPrefix("/webapp/");// irv.setSuffix(".jsp"); irv.setViewClass(JstlView.class); return irv; }}
web.xml文件之WebApplicationInitializer接口类
package com.csl.demo.annotation;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.ServletRegistration.Dynamic;import org.springframework.web.WebApplicationInitializer;import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;import org.springframework.web.servlet.DispatcherServlet;/** * @author Cherry * @date 2017年10月3日 */public class WebConfig implements WebApplicationInitializer{ /* (non-Javadoc) * @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext) */ @Override public void onStartup(ServletContext sc) throws ServletException { //注意:不是AnnotationConfigApplicationContext类 AnnotationConfigWebApplicationContext config = new AnnotationConfigWebApplicationContext(); //配置类注册到web容器 config.register(SpringCongfigs.class); //设置ServletContext config.setServletContext(sc); Dynamic servlet = sc.addServlet("dispatcherServlet", new DispatcherServlet(config)); //添加映射路径 servlet.addMapping("/"); //设置启动顺序 servlet.setLoadOnStartup(1); }}
@Controller类
/** * */package com.csl.demo.annotation;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;/** * @author Cherry * @date 2017年10月3日 */@Controllerpublic class HelloController { @RequestMapping("/hello") public String hello() { System.out.println("方法执行了!!"); return "hello.jsp"; }}
pom.xml文件
<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.0</modelVersion> <groupId>com.csl.demo</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>demo</name> <description /> <properties> <webVersion>3.0</webVersion> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.3.11.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>4.3.11.RELEASE</version> </dependency> <dependency> <groupId>org.glassfish.web</groupId> <artifactId>javax.servlet.jsp.jstl</artifactId> <version>1.2.2</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build></project>
阅读全文
0 0
- 无配置文件实现简单web工程
- web工程加载配置文件
- web工程中使用配置文件
- Spring Web Flow 简单实现-自定义配置文件位置
- 简单的Java Web工程,实现登录注册
- myeclipse创建web工程无响应
- Web.xml文件 - 工程初始化配置文件
- Web.xml文件 - 工程初始化配置文件解析
- maven创建web工程找不到Spring配置文件
- web工程中读取properties配置文件方法
- Web工程中配置文件路径问题
- maven创建web工程找不到Spring配置文件
- Spring --web工程下xml配置文件部署
- 简单的无扩展Vim配置文件
- web.xml配置文件简单介绍
- openfire 插件web工程web-custom.xml配置文件说明
- 解读WEB工程下的web.xml配置文件
- android工程里,配置文件的实现。
- 数学游戏之乐------给出方案数,求总额&&面额?
- [Haskell] CodeWars|Growth of a Population
- 阿里云服务器centos7.3安装lamp环境(PHP版本为7.0,数据为mysql)根据网上文章整理笔记
- 《Java核心技术》第10版读书笔记之Chap5(2)——方法调用过程、final、类型转换、abstract与访问标识符
- 数据的操作 标准语言SQL
- 无配置文件实现简单web工程
- 13:图像模糊处理
- 利用方程组系数向量是否共面来判断解的唯一性
- 数据结构-实现俩链表(int)拼接后还是有序的
- 为国庆献礼:无人智能系统,守护祖国海空长城
- 16杭州ccpc Equation HDU
- Set集合及其实现类
- 选择排序
- iOS delegate、NSNotification效率比较