01--springmvc分布式项目Web项目配置

springmvc的配置文件,放在resources目录下:

文件名:applicationContext-mvc.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xmlns:p="http://www.springframework.org/schema/p"
 6        xmlns:util="http://www.springframework.org/schema/util"
 7        xmlns:aop="http://www.springframework.org/schema/aop"
 8        xmlns:tx="http://www.springframework.org/schema/tx"
 9        xmlns:mvc="http://www.springframework.org/schema/mvc"
10        xsi:schemaLocation="
11 http://www.springframework.org/schema/beans
12 http://www.springframework.org/schema/beans/spring-beans.xsd
13 http://www.springframework.org/schema/context
14 http://www.springframework.org/schema/context/spring-context.xsd
15 http://www.springframework.org/schema/tx
16 http://www.springframework.org/schema/tx/spring-tx.xsd
17 http://www.springframework.org/schema/aop
18 http://www.springframework.org/schema/aop/spring-aop.xsd
19 http://www.springframework.org/schema/mvc
20 http://www.springframework.org/schema/mvc/spring-mvc.xsd
21 http://www.springframework.org/schema/util
22 http://www.springframework.org/schema/util/spring-util.xsd">
23 
24     <!-- dispatcherServlet 截获所有 URL 请求 -->
25     <mvc:default-servlet-handler/>
26 
27     <!-- spring mvc 扫描包下的 controller -->
28     <context:component-scan base-package="com.bjpowernode.p2p.web"/>
29 
30     <!-- 配置注解驱动 -->
31     <mvc:annotation-driven/>
32 
33     <!-- 配置视图解析器 -->
34     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
35         <property name="prefix" value="/"/>
36         <property name="suffix" value=".jsp"/>
37     </bean>
38 
39 
40 
41 </beans>

spring总的配置文件

文件名:applicationContext.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xmlns:p="http://www.springframework.org/schema/p"
 6        xmlns:aop="http://www.springframework.org/schema/aop"
 7        xmlns:tx="http://www.springframework.org/schema/tx"
 8        xmlns:task="http://www.springframework.org/schema/task"
 9        xsi:schemaLocation="
10 http://www.springframework.org/schema/beans
11 http://www.springframework.org/schema/beans/spring-beans.xsd
12 http://www.springframework.org/schema/context
13 http://www.springframework.org/schema/context/spring-context.xsd
14 http://www.springframework.org/schema/tx
15 http://www.springframework.org/schema/tx/spring-tx.xsd
16 http://www.springframework.org/schema/aop
17 http://www.springframework.org/schema/aop/spring-aop.xsd">
18 
19 
20     <!-- 导入 spring mvc 配置 -->
21     <import resource="applicationContext-mvc.xml" />
22     <!-- 导入服务提供者配置 -->
23     <import resource="applicationContext-dubbo-consumer.xml"/>
24 </beans>

log4j配置

文件名称:log4j2.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <configuration status="info">
 3     <!--先定义所有的 appender-->
 4     <appenders>
 5         <!--这个输出控制台的配置-->
 6         <Console name="Console" target="SYSTEM_OUT">
 7             <!--控制台只输出 level 及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
 8             <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="ACCEPT"/>
 9             <!--这个都知道是输出日志的格式-->
10             <PatternLayout pattern="[p2p] %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>
11         </Console>
12         <!--这个会打印出所有的信息,每次大小超过 size,则这 size 大小的日
13         志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
14         <RollingFile name="RollingFile"
15                      fileName="/opt/tomcat_licaihost/logs/app.log"
16                      filePattern="/opt/tomcat_licaihost/logs/$${date:yyyy-MM}/app -%d{MM-dd-yyyy}-%i.log.gz">
17             <PatternLayout pattern="[p2p] %d{yyyy-MM-dd 'at' HH:mm:ss z} %-5level %class{36} %L %M - %msg%xEx%n"/>
18             <SizeBasedTriggeringPolicy size="300MB"/>
19         </RollingFile>
20     </appenders>
21     <!--然后定义 logger,只有定义了 logger 并引入 appender,appender 才会生效-->
22     <loggers>
23         <!--建立一个默认的 root 的 logger-->
24         <root level="info">
25             <appender-ref ref="Console"/>
26             <appender-ref ref="RollingFile"/>
27         </root>
28     </loggers>
29 </configuration>

dubbo的配置文件,消费者

文件名:applicationContext-dubbo-consumer.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
 5        xsi:schemaLocation="http://www.springframework.org/schema/beans
 6 http://www.springframework.org/schema/beans/spring-beans.xsd
 7 http://code.alibabatech.com/schema/dubbo
 8 http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
 9 
10     <!-- 配置应用名称 -->
11     <dubbo:application name="p2p"/>
12 
13     <!-- 配置注册中心 -->
14     <dubbo:registry protocol="zookeeper" address="192.168.127.128:2181"/>
15 
16     <!--产品业务-->
17     <dubbo:reference id="loanInfoService" interface="com.bjpowernode.p2p.service.loan.LoanInfoService" version="1.0.0" check="false"></dubbo:reference>
18 
19     <!--用户业务-->
20     <dubbo:reference id="userService" interface="com.bjpowernode.p2p.service.loan.UserService" version="1.0.0" check="false"></dubbo:reference>
21 
22     <!--投资业务-->
23     <dubbo:reference id="bidInfoService" interface="com.bjpowernode.p2p.service.loan.BidInfoService" version="1.0.0" check="false"></dubbo:reference>
24 
25     <!--帐户业务-->
26     <dubbo:reference id="financeAccountService" interface="com.bjpowernode.p2p.service.user.FinanceAccountService" version="1.0.0" check="false"></dubbo:reference>
27 
28     <!--redis业务-->
29     <dubbo:reference id="redisService" interface="com.bjpowernode.p2p.service.loan.RedisService" version="1.0.0" check="false"></dubbo:reference>
30 
31     <!--收益业务-->
32     <dubbo:reference id="incomeRecordService" interface="com.bjpowernode.p2p.service.loan.IncomeRecordService" version="1.0.0" check="false"></dubbo:reference>
33 
34     <!--充值业务-->
35     <dubbo:reference id="rechargeRecordService" interface="com.bjpowernode.p2p.service.loan.RechargeRecordService" version="1.0.0" timeout="15000"></dubbo:reference>
36 
37 
38 </beans>

WEB_INF下的配置文件web.xml配置

文件名:web.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app
 3         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4         xmlns="http://java.sun.com/xml/ns/javaee"
 5         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 6 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 7         id="WebApp_ID" version="3.0">
 8     <!-- 应用名 -->
 9     <display-name>p2p</display-name>
10     <!-- 字符过滤器,字符编码 UTF-8 -->
11     <filter>
12         <filter-name>encodingFilter</filter-name>
13         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
14         <init-param>
15             <param-name>encoding</param-name>
16             <param-value>UTF-8</param-value>
17         </init-param>
18     </filter>
19     <filter-mapping>
20         <filter-name>encodingFilter</filter-name>
21         <url-pattern>/*</url-pattern>
22     </filter-mapping>
23     <!-- Spring mvc 分发 servlet -->
24     <servlet>
25         <servlet-name>dispatcher</servlet-name>
26         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
27         <init-param>
28             <param-name>contextConfigLocation</param-name>
29             <param-value>classpath:applicationContext.xml</param-value>
30         </init-param>
31         <load-on-startup>1</load-on-startup>
32     </servlet>
33     <servlet-mapping>
34         <servlet-name>dispatcher</servlet-name>
35         <url-pattern>/</url-pattern>
36     </servlet-mapping>
37     <servlet-mapping>
38         <servlet-name>dispatcher</servlet-name>
39         <url-pattern>/index</url-pattern>
40     </servlet-mapping>
41     <!-- 欢迎页,默认进入 index controller -->
42     <welcome-file-list>
43         <welcome-file>index</welcome-file>
44     </welcome-file-list>
45 </web-app>
原文地址:https://www.cnblogs.com/Tpf386/p/10982177.html