1、service层
package com.real.supporter.services.bean;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.List;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Mirror;
import org.nutz.log.Logs;
import com.real.supporter.commons.ResultCode;
import com.real.supporter.models.bean.ModelConfig;
import cn.wizzer.common.base.Service;
/**
*
* @author Readitec
* @time
*/
@IocBean(args = {"refer:dao"})
public class ModelConfigService extends Service<ModelConfig> {
public ModelConfigService(Dao dao) {
super(dao);
}
public ResultCode ModelSubmit(ModelConfig modelConf, String modelPath,List<String> nameList,
List<String> rgb_rList,List<String> rgb_gList,List<String> rgb_bList,List<String> bgList) {
try {
if(null==modelConf ) {
Logs.get().error(ResultCode.PARAMETER_IS_NULL.getMessage());
return ResultCode.PARAMETER_IS_NULL;
}
Mirror<ModelConfig> mirror =Mirror.me(ModelConfig.class);
//name
if (nameList!=null) {
for (int i = 0; i < nameList.size(); i++) {
Method method = mirror.getSetter("name"+i, String.class);
try {
method.invoke(modelConf, nameList.get(i-1));
} catch (Exception e) {
Logs.get().error(e);
}
}
}
//rgb_r
if (rgb_rList!=null) {
for (int i = 0; i < rgb_rList.size(); i++) {
Method method = mirror.getSetter("rgb_r"+i, String.class);
try {
method.invoke(modelConf, rgb_rList.get(i-1));
} catch (Exception e) {
Logs.get().error(e);
}
}
}
//rgb_g
if (rgb_gList!=null) {
for (int i = 0; i < rgb_gList.size(); i++) {
Method method = mirror.getSetter("rgb_g"+i, String.class);
try {
method.invoke(modelConf, rgb_gList.get(i-1));
} catch (Exception e) {
Logs.get().error(e);
}
}
}
//rgb_b
if (rgb_bList!=null) {
for (int i = 0; i < rgb_bList.size(); i++) {
Method method = mirror.getSetter("rgb_b"+i, String.class);
try {
method.invoke(modelConf, rgb_bList.get(i-1));
} catch (Exception e) {
Logs.get().error(e);
}
}
}
//rgb_g
if (bgList!=null) {
for (int i = 0; i < bgList.size(); i++) {
Method method = mirror.getSetter("bg"+i, String.class);
try {
method.invoke(modelConf, bgList.get(i-1));
} catch (Exception e) {
Logs.get().error(e);
}
}
}
modelConf.setUpload_date(new Date());
this.insert(modelConf);
return ResultCode.SUCCESS;
} catch (Exception e) {
Logs.get().error("模型配置遇到了错误!");
Logs.get().error(e);
}
return ResultCode.FAIL;
}
}
2、module层
@AdaptBy(type=UploadAdaptor.class,args = { "ioc:fileUpload" })
@At("/upload")
@Ok("redirect:/real/list")
@Fail("jsp:jsp.500")
public Object upload(String orderId, ModelConfig modelConf,
@Param("names") String[] names, @Param("rgb_rs") String[] rgb_rs, @Param("rgb_gs") String[] rgb_gs,
@Param("rgb_bs") String[] rgb_bs, @Param("bgs") String[] bgs,
@Param("file_image") TempFile tf, @Attr("user") User currentUser, String repositoryName, String orderNum,
AdaptorErrorContext err) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
if(Strings.isEmpty(orderId) || Strings.isEmpty(repositoryName)) {
map.put("status", ResultCode.PARAMETER_IS_NULL.getCode());
map.put("message", ResultCode.PARAMETER_IS_NULL.getMessage());
}
ResultCode rc = ResultCode.FAIL;
if (err != null && err.getAdaptorErr() != null) {
rc.setMessage("文件大小不符合规定");
} else if (tf == null) {
rc.setMessage("空文件");
} else {
try {
// Files.copyFile(tf.getFile(),new File("d:/filesrv/"+tf.getName()));
BufferedImage image = Images.read(tf.getFile());
image = Images.zoomScale(image, 300, 190, Color.BLACK);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Images.writeJpeg(image, out, 0.8f);
//获取模型上传路径
String modelPath = FilePathUtils.generateServerFilePath(repositoryName, orderNum);
List<String> nameList = Lang.array2list(names);
List<String> rgb_rList = Lang.array2list(rgb_rs);
List<String> rgb_gList = Lang.array2list(rgb_gs);
List<String> rgb_bList = Lang.array2list(rgb_bs);
List<String> bgList = Lang.array2list(bgs);
rc = serModel.modelFinished(orderId, currentUser.getUuid(), modelPath, out.toByteArray(),
modelConf, nameList, rgb_rList, rgb_gList, rgb_bList, bgList);
rc = modelconf.ModelSubmit(modelConf, modelPath, nameList, rgb_rList, rgb_gList, rgb_bList, bgList);
} catch(Exception e) {
Logs.get().error(e);
rc.setMessage("系统错误");
} catch (Throwable e) {
Logs.get().error(e);
rc.setMessage("图片格式错误");
}
}
map.put("status", rc.getCode());
map.put("message", rc.getMessage());
return map;
}
3、日志
2018-02-01 16:33:08,612 DEBUG Found mapping for [GET] path=/rebuild/to_upload/17463425426b4e6a9aa8d10e2cf74453 : RebuildModule.toUpload(RebuildModule.java:300) - org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101)
2018-02-01 16:33:08,658 WARN Error@/rebuild/to_upload/17463425426b4e6a9aa8d10e2cf74453 : - org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28)
org.nutz.ioc.IocException: IocBean[rebuildModule] throw Exception when creating
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:110)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: IocBean[rebuildModule] fail at field=[modelconf]
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
... 42 more
Caused by: org.nutz.ioc.IocException: IocBean[ModelConfigService] For object [ModelConfigService] - type:[]
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
... 44 more
Caused by: org.nutz.ioc.ObjectLoadException: Object 'ModelConfigService' without define!
at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:166)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
... 46 more
麻烦你看看,我对比另一个正常的service,找了很久没发现哪儿不对。ioc应该无误