案例
今天在跟着nutz框架教程去配置demo时,发现访问URL找不到入口函数,出现了Search mapping for path=/user/count : NOT Action match 异常,据nutz文档介绍,找不到方法, 一般是@At写错或者UserModule的package写错,导致映射不到或者根本没找到这个类,于是我从这个两个方面入手,最后还是出现404
package com.evanshare.module;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.Ok;
import com.evanshare.bean.User;
@IocBean
@At("/user/")
@Ok("json")
@Fail("http:500")
public class UserModule {
@Inject
protected Dao dao;
@At("count")
public int count(){
return dao.count(User.class);
}
}
package com.evanshare.main;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.annotation.Modules;
import org.nutz.mvc.annotation.SetupBy;
import org.nutz.mvc.ioc.provider.ComboIocProvider;
import com.evanshare.module.UserModule;
@SetupBy(value=MainSetup.class)
@IocBy(type=ComboIocProvider.class,args={"*js","config/ioc/","*anno","com.evanshare","*tx"})
@Modules(scanPackage=true)
public class MainModule {
}
项目结构如下:
解决方案
1.后来我尝试修改MainModule上的@Modules注解,指定入口函数,结果可以访问,由此可见该问题是因为扫包有问题,导致之前根本没有加载到UserModule.class
@SetupBy(value=MainSetup.class)
@IocBy(type=ComboIocProvider.class,args={"*js","config/ioc/","*anno","com.evanshare","*tx"})
@Modules(UserModule.class)
public class MainModule {
}