A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

【郑州校区】传智健康项目讲义第六章五

2.2.3 health_mobile
创建移动端工程health_mobile,打包方式为war,用于存放Controller,在Controller通过Dubbo可以远程访问服务层相关服务,所以需要依赖health_interface接口工程。
pom.xml
[AppleScript] 纯文本查看 复制代码
<?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
[url]http://maven.apache.org/xsd/maven[/url]‐
4.0.0.xsd">
<parent>
<artifactId>health_parent</artifactId>
<groupId>com.itheima</groupId>
<version>1.0‐SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>health_mobile</artifactId>
<packaging>war</packaging>
<name>healthmobile_web Maven Webapp</name>
<url>[url]http://www.example.com[/url]</url>
<properties>
<project.build.sourceEncoding>UTF‐
8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>health_interface</artifactId>
<version>1.0‐SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7‐maven‐plugin</artifactId>
<configuration>
<!‐‐ 指定端口 ‐‐>
<port>80</port>
<!‐‐ 请求路径 ‐‐>
<path>/</path></configuration>
</plugin>
</plugins>
</build>
</project> 

静态资源(CSShtmlimg等,详见资料):

web.xml
[AppleScript] 纯文本查看 复制代码
 <!DOCTYPE web‐app PUBLIC
"‐//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web‐app_2_3.dtd" >
<web‐app>
<display‐name>Archetype Created Web Application</display‐name>
<!‐‐ 解决post乱码 ‐‐>
<filter>
<filter‐name>CharacterEncodingFilter</filter‐name>
<filter‐
class>org.springframework.web.filter.CharacterEncodingFilter</filter‐
class>
<init‐param>
<param‐name>encoding</param‐name>
<param‐value>utf‐8</param‐value>
</init‐param>
<init‐param>
<param‐name>forceEncoding</param‐name>
<param‐value>true</param‐value>
</init‐param>
</filter>
<filter‐mapping>
<filter‐name>CharacterEncodingFilter</filter‐name>
<url‐pattern>/*</url‐pattern>
</filter‐mapping>
<servlet>
<servlet‐name>springmvc</servlet‐name>
<servlet‐
class>org.springframework.web.servlet.DispatcherServlet</servlet‐class>
<!‐‐ 指定加载的配置文件 ,通过参数contextConfigLocation加载 ‐‐>
<init‐param>
<param‐name>contextConfigLocation</param‐name>
<param‐value>classpath:springmvc.xml</param‐value>
</init‐param>
<load‐on‐startup>1</load‐on‐startup>
</servlet>
<servlet‐mapping>
<servlet‐name>springmvc</servlet‐name>
<url‐pattern>*.do</url‐pattern>
</servlet‐mapping>
<welcome‐file‐list><welcome‐file>/pages/index.html</welcome‐file>
</welcome‐file‐list>
</web‐app> 


springmvc.xml

[AppleScript] 纯文本查看 复制代码
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
[url]http://www.springframework.org/schema/beans/spring[/url]‐beans.xsd
[url]http://www.springframework.org/schema/mvc[/url]
[url]http://www.springframework.org/schema/mvc/spring[/url]‐mvc.xsd
[url]http://code.alibabatech.com/schema/dubbo[/url]
[url]http://code.alibabatech.com/schema/dubbo/dubbo.xsd[/url]
[url]http://www.springframework.org/schema/context[/url]
[url]http://www.springframework.org/schema/context/spring[/url]‐
context.xsd">
<mvc:annotation‐driven>
<mvc:message‐converters register‐defaults="true">
<bean
class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json"/>
<property name="features">
<list>
<value>WriteMapNullValue</value>
<value>WriteDateUseDateFormat</value>
</list>
</property>
</bean>
</mvc:message‐converters>
</mvc:annotation‐driven>
<!‐‐ 指定应用名称 ‐‐>
<dubbo:application name="health_mobile" />
<!‐‐指定服务注册中心地址‐‐>
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<!‐‐批量扫描‐‐>
<dubbo:annotation package="com.itheima.controller" />
<!‐‐
超时全局设置 10分钟
check=false 不检查服务提供方,开发阶段建议设置为falsecheck=true 启动时检查服务提供方,如果服务提供方没有启动则报错
‐‐>
<dubbo:consumer timeout="600000" check="false"/>
<import resource="spring‐redis.xml"></import>
</beans> 

spring-redis.xml

[AppleScript] 纯文本查看 复制代码
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
[url]http://www.springframework.org/schema/beans/spring[/url]‐beans.xsd
[url]http://www.springframework.org/schema/mvc[/url]
[url]http://www.springframework.org/schema/mvc/spring[/url]‐mvc.xsd
[url]http://code.alibabatech.com/schema/dubbo[/url]
[url]http://code.alibabatech.com/schema/dubbo/dubbo.xsd[/url]
[url]http://www.springframework.org/schema/context[/url]
[url]http://www.springframework.org/schema/context/spring[/url]‐
context.xsd">
<context:property‐placeholder location="classpath:redis.properties"
/>
<!‐‐Jedis连接池的相关配置‐‐>
<bean id="jedisPoolConfig"
class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal">
<value>${redis.pool.maxActive}</value>
</property>
<property name="maxIdle">
<value>${redis.pool.maxIdle}</value>
</property>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
</bean>
<bean id="jedisPool" class="redis.clients.jedis.JedisPool">
<constructor‐arg name="poolConfig" ref="jedisPoolConfig" />
<constructor‐arg name="host" value="${redis.host}" />
<constructor‐arg name="port" value="${redis.port}" type="int" />
<constructor‐arg name="timeout" value="${redis.timeout}"
type="int" />
</bean></beans> 

redis.properties
#最大分配的对象数
redis.pool.maxActive=200
#最大能够保持idel状态的对象数
redis.pool.maxIdle=50
redis.pool.minIdle=10
redis.pool.maxWaitMillis=20000
#当池内没有返回对象时,最大等待时间
redis.pool.maxWait=300
#格式:redis://:[密码]@[服务器地址]:[端口]/[db index]
#redis.uri = redis://:12345@127.0.0.1:6379/0
redis.host = 127.0.0.1
redis.port = 6379
redis.timeout = 30000
log4j.properties


### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L
‐ %m%n
### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c:\\mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L ‐
%m%n
### set log levels ‐ for more verbose logging change 'info' to 'debug'
###
log4j.rootLogger=info, stdout



0 个回复

您需要登录后才可以回帖 登录 | 加入黑马