Java之SpringMVC(5分钟搭建Web工程)

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”>

4.0.0

cn.itbluebox

dubbo-web

1.0-SNAPSHOT

<spring.version>5.1.9.RELEASE</spring.version>

<dubbo.version>2.7.4.1</dubbo.version>

<zookeeper.version>4.0.0</zookeeper.version>

javax.servlet

javax.servlet-api

3.1.0

provided

org.springframework

spring-context

${spring.version}

org.springframework

spring-webmvc

${spring.version}

org.slf4j

slf4j-api

1.7.21

org.slf4j

slf4j-log4j12

1.7.21

org.apache.dubbo

dubbo

${dubbo.version}

org.apache.curator

curator-framework

${zookeeper.version}

org.apache.curator

curator-recipes

${zookeeper.version}

org.apache.tomcat.maven

tomcat7-maven-plugin

2.1

8000

/

2、在dubbo-service当中引入依赖

在这里插入图片描述

<?xml 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”>

4.0.0

cn.itbluebox

dubbo-service

1.0-SNAPSHOT

<spring.version>5.1.9.RELEASE</spring.version>

<dubbo.version>2.7.4.1</dubbo.version>

<zookeeper.version>4.0.0</zookeeper.version>

javax.servlet

javax.servlet-api

3.1.0

provided

org.springframework

spring-context

${spring.version}

org.springframework

spring-webmvc

${spring.version}

org.slf4j

slf4j-api

1.7.21

org.slf4j

slf4j-log4j12

1.7.21

org.apache.dubbo

dubbo

${dubbo.version}

org.apache.curator

curator-framework

${zookeeper.version}

org.apache.curator

curator-recipes

${zookeeper.version}

四、编写Service和对应的实现类


在这里插入图片描述

在这里插入图片描述

package com.itbluebox.service;

public interface UserService {

public String sayHello();

}

在这里插入图片描述

在这里插入图片描述

package com.itbluebox.service.impl;

import com.itbluebox.service.UserService;

import org.springframework.stereotype.Service;

@Service

public class UserServiceImpl implements UserService {

@Override

public String sayHello() {

return “hello dubbo!~”;

}

}

1、创建相关的配置文件

  • applicationContext.xml

在这里插入图片描述

<?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:dubbo=“http://dubbo.apache.org/schema/dubbo” 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://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">

<context:component-scan base-package=“com.itbluebox.service”/>

  • log4j.properties

在这里插入图片描述

DEBUG < INFO < WARN < ERROR < FATAL

Global logging configuration

log4j.rootLogger=info, stdout,file

My logging configuration…

#log4j.logger.com.tocersoft.school=DEBUG

#log4j.logger.net.sf.hibernate.cache=debug

Console output…

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%5p %d %C: %m%n

log4j.appender.file=org.apache.log4j.FileAppender

log4j.appender.file.File=…/logs/iask.log

log4j.appender.file.layout=org.apache.log4j.PatternLayout

log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %l %m%n

五、编写controller


1、修改一下配置文件

在这里插入图片描述

war

2、创建对应的目录和web.xml

在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xmlns=“http://java.sun.com/xml/ns/javaee”

xsi:schemaLocation=“http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd”

version=“2.5”>

contextConfigLocation

classpath*:spring/applicationContext*.xml

org.springframework.web.context.ContextLoaderListener

springmvc

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring/springmvc.xml

springmvc

*.do

设置一下依赖

dubbo-web 依赖dubbo-service

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值