??xml version="1.0" encoding="utf-8" standalone="yes"?> 使用@RequestParamӞURL是这LQhttp://host:port/path?参数?参数?br style="margin: 0px; padding: 0px;" /> 使用@PathVariableӞURL是这LQhttp://host:port/path/参数?br style="margin: 0px; padding: 0px;" /> 例如Q?/p> 上面两个ҎQ访问\径分别如下:
]]>
]]>
g我也是苦思良久,不经意间看到了后台的日志Q才发现是spring搞的鬹{?/span>
报错信息Q?span style="box-sizing: border-box; margin: 0px; padding: 0px; color: #ff0000;"><No mapping found for HTTP request with URI [/sandDemo001/images/1.jpg] in DispatcherServlet with name 'spring'>
解决Ҏ1Q?span style="box-sizing: border-box; margin: 0px; padding: 0px; font-size: 14px;">在spring的配|修?/strong>web.xml下对spring?/strong>DispatcherServlethurl映射的配|,先来看看原配|?/strong>Q?/span>
解决Ҏ2Q?span style="box-sizing: border-box; margin: 0px; padding: 0px; color: #000000; font-size: 14px;">在spring的配|文件中d如下一行:
<mvc:default-servlet-handler/>
注意Q需要是spring3.0.5以上版本
摘自Q?a style="text-decoration: none; color: #000000;">http://www.oschina.net/p/fastdfs
FastDFS是一个开源的分布式文件系l,她对文gq行理Q功能包括:文g存储、文件同步、文件访问(文g上传、文件下载){,解决了大定w存储和负载均衡的问题。特别适合以文件ؓ载体的在U服务,如相册网站、视频网站等{?/p>
FastDFS服务端有两个角色Q跟t器QtrackerQ和存储节点QstorageQ。跟t器主要做调度工作,在访问上赯载均衡的作用?/p>
存储节点存储文gQ完成文件管理的所有功能:存储、同步和提供存取接口QFastDFS同时Ҏ件的meta dataq行理。所谓文件的meta data是文g的相兛_性,以键值对Qkey value pairQ方式表C,如:width=1024Q其中的key为widthQvalue?024。文件meta data是文件属性列表,可以包含多个键值对?/p>
GitHubQ?a style="text-decoration: none; color: #000000;">https://github.com/happyfish100/fastdfs
一个写的不错的博客Q?a style="text-decoration: none; color: #000000;">http://tech.uc.cn/?p=221
参考文档:
https://github.com/happyfish100/fastdfs/blob/master/INSTALL
yum -y groupinstall 'Development Tools' yum -y install wget
必须先按照这个,否则报错Q?/p>
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o ../common/fdfs_global.o ../common/fdfs_global.c -I../common -I/usr/include/fastcommon ../common/fdfs_global.c:20:20: fatal error: logger.h: No such file or directory #include "logger.h" ^ compilation terminated. ........
直接下蝲安装卛_Q?/p>
wget https://github.com/happyfish100/libfastcommon/archive/master.zip unzip master.zip cd libfastcommon-master ./make.sh ./make.sh install
wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz tar -zxvf V5.05.tar.gz cd fastdfs-5.05/ ./make.sh ./make.sh install
安装之后配置文g在目?etc/fdfs?/p>
mv storage.conf.sample storage.conf mv tracker.conf.sample tracker.conf
首先修改配置文gQ?nbsp;
/etc/fdfs/tracker.confQ修改\径到/data/fdfs目录?/p>
# the base path to store data and log files base_path=/data/fdfs
启动Q?nbsp;
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
修改配置文gQ?nbsp;
/etc/fdfs/storage.confQ修改\径到/data/fdfs目录Q同旉|tracker_server地址?/p>
# the base path to store data and log files base_path=/data/fdfs # tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address tracker_server=192.168.1.36:22122 # store_path#, based 0, if store_path0 not exists, it's value is base_path # the paths must be exist store_path0=/data/fdfs #store_path1=/home/yuqing/fastdfs2
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
启动的时候,看日志没有错误就说明启动成功?nbsp;
查看fdfsq程Q?/p>
#ps -ef | grep fdfs root 19880 1 0 21:42 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start root 20050 1 0 22:08 ? 00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start root 20060 19915 0 22:08 pts/1 00:00:00 grep --color=auto fdfs
2.5 安装nginx + lua + fastdfs module
下蝲fastdfs-nginx-module模块
https://github.com/happyfish100/fastdfs-nginx-module
下蝲openresty nginx +lua?/p>
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip unzip fastdfs-nginx-module-master.zip wget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz tar -zxvf ngx_openresty-1.7.10.1.tar.gz
~译安装Q这里注意下Q需要增加参数?nbsp;
一个是stub_statusl计模块Q一个是realip模块?nbsp;
参考地址Q?nbsp;
http://blog.danielss.com/?p=80
http://wiki.nginx.org/HttpRealipModuleChs
yum -y install pcre-devel openssl openssl-devel cd ngx_openresty-1.7.10.1 ./configure --with-luajit --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=/root/fastdfs-nginx-module-master/src gmake gmake install
nginx +lua安装路径Q?/p>
nginx path prefix: "/usr/local/openresty/nginx" nginx binary file: "/usr/local/openresty/nginx/sbin/nginx" nginx configuration prefix: "/usr/local/openresty/nginx/conf" nginx configuration file: "/usr/local/openresty/nginx/conf/nginx.conf" nginx pid file: "/usr/local/openresty/nginx/logs/nginx.pid" nginx error log file: "/usr/local/openresty/nginx/logs/error.log" nginx http access log file: "/usr/local/openresty/nginx/logs/access.log"
启动Q重启nginx
#启动 /usr/local/openresty/nginx/sbin/nginx #重启 /usr/local/openresty/nginx/sbin/nginx -s restart
配置服务Q?/p>
cd /etc/fdfs mv client.conf.sample client.conf
修改配置Q?/p>
# the base path to store log files base_path=/data/fdfs # tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address tracker_server=192.168.1.36:22122
配置nginxQ?/p>
cp /root/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/ mkdir /data/ngx
修改mod_fastdfs.conf配置文gQ修改tracker端口Q否则nginx启动不了。\径也必须修改Q否则找不到文g?/p>
# the base path to store log files base_path=/data/ngx # FastDFS tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address # valid only when load_fdfs_parameters_from_tracker is true tracker_server=192.168.1.36:22122 # store_path#, based 0, if store_path0 not exists, it's value is base_path # the paths must be exist # must same as storage.conf store_path0=/data/fdfs
拯配置文gQ否则nginx启动不了Q报错:
[2015-04-28 11:30:14] ERROR - file: ini_file_reader.c, line: 315, include file "http.conf" not exists, line: "#include http.conf" [2015-04-28 11:30:14] ERROR - file: /root/fastdfs-nginx-module-master/src/common.c, line: 155, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2 2015/04/28 11:30:14 [alert] 19969#0: worker process 2753 exited with fatal code 2 and cannot be respawned
解决办法Q?/p>
cp /root/fastdfs-master/conf/http.conf /root/fastdfs-master/conf/mime.types /etc/fdfs
nginx配置修改vi /usr/local/openresty/nginx/conf/nginx.conf
server { listen 80; server_name localhost; charset utf8; location /M00 { alias /data/fdfs/data; ngx_fastdfs_module; } ......
创徏q接
ln -s /data/fdfs/data /data/fdfs/data/M00
重启nginx?nbsp;
试命oQ?/p>
echo "test fastdfs" > test.html /usr/bin/fdfs_test /etc/fdfs/client.conf upload test.html
上传成功Q执行结果:
This is FastDFS client test program v5.05 Copyright (C) 2008, Happy Fish / YuQing FastDFS may be copied only under the terms of the GNU General Public License V3, which may be found in the FastDFS source kit. Please visit the FastDFS Home Page http://www.csource.org/ for more detail. [2015-04-25 18:06:09] DEBUG - base_path=/data/fdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0 tracker_query_storage_store_list_without_group: server 1. group_name=, ip_addr=192.168.1.36, port=23000 group_name=group1, ip_addr=192.168.1.36, port=23000 storage_upload_by_filename group_name=group1, remote_filename=M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01.html source ip address: 192.168.1.36 file timestamp=2015-04-25 18:06:09 file size=13 file crc32=3418468952 example file url: http://192.168.1.36/group1/M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01.html storage_upload_slave_by_filename group_name=group1, remote_filename=M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01_big.html source ip address: 192.168.1.36 file timestamp=2015-04-25 18:06:09 file size=13 file crc32=3418468952 example file url: http://192.168.1.36/group1/M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01_big.html
试讉KQ?/p>
curl http://192.168.1.36/M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01_big.html
如果q回“test fastdfs”说明配置成功。上面的每一步修攚w要正才可以?/p>
查看nginx错误日志Q?nbsp;
tail -f /usr/local/openresty/nginx/logs/error.log
FastDFS非常好的分布式文件系l。配|简单,可以多机器部|Ԍ同时官方l了一个Nginx模块Q可以直接用nginx讉KQ非常方ѝ这样减了中间的tomcat层,效率高?nbsp;
接下来l研Ilua的图片压~。直接在nginx层进行图片压~。效率更高,同时囄dFastDFS的文件?/p>
场景Q在ServicecM使用子事?saveponit)Ӟ当子事务抛出异常后,此异常处理掉不l往外抛Qspring在提交主事务时会抛出
org.springframework.transaction.UnexpectedRollbackException: Transaction has been rolled back because it has been marked as rollback
Ҏ调用l构Q?/p>
假若有A、B、C三个Servicec,其实例对象分别ؓa、b、c,cd别定义如下:
A {
Ҏ() { //propagation="REQUIRED"
try{
b.Ҏ();
} catch (Exception e) {
}
}
}
B{
savePointҎ() { //propagation="NESTED"
c.Ҏ(); //如果q里边的操作全是普通类Q不是Servicec)操作Q不会有问题?/p>
}
}
C{
Ҏ() { //propagation="REQUIRED"
throw new Exception("出错");
}
}
通过调试spring源码
......
Getting transaction for [A.Ҏ] .....
......
Creating nested transaction with name [B.savePointҎ]........
......
Participating in existing transaction
Getting transaction for [C.Ҏ]
........
Participating transaction failed - marking existing transaction as rollback-only
//此时Q已把主事务标记成了rollback-only
所以,当在a.Ҏ完成时提交事务时会报Transaction has been rolled back because it has been marked as rollback错误?/p>
认真的您可能会发玎ͼ?org.springframework.transaction.support.AbstractPlatformTransactionManager 中有个叫
isGlobalRollbackOnParticipationFailure的参敎ͼ默认是true.
源码中说明:
Switch this to "false" to let the transaction originator make the rollback decision. If a participating transaction fails with an exception, the caller can still decide to continue with a different path within the transaction. However, note that this will only work as long as all participating resources are capable of continuing towards a transaction commit even after a data access failure: This is generally not the case for a Hibernate Session, for example; neither is it for a sequence of JDBC insert/update/delete operations.
大意是:如果isGlobalRollbackOnParticipationFailure为false,则会让主事务军_回滚Q如果当遇到exception加入事务p|Ӟ调用者能l箋在事务内军_是回滚还是l。然而,要注意是那样做仅仅适用于在数据讉Kp|的情况下且只要所有操作事务能提交?/p>
初步解决ҎQ?/p>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> <property name="globalRollbackOnParticipationFailure" value="false" /> <!--指定此参Cؓfalse-->
</bean>
l测试,此问题暂时得到解冻I不知道会不会引v其它问题Q至目前还没有发现其它异常。您若通过此方案解决之后出C新的问题L信回复,我们一起交,非常感谢Q?/p>