NutzCN Logo
问答 求指教!userModule求帮助
发布于 2889天前 作者 chafferer 1581 次浏览 复制 上一个帖子 下一个帖子
标签:

mainModule:

package com.cdroid.nutz;

import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.annotation.Modules;
import org.nutz.mvc.annotation.Ok;

@Modules(scanPackage = true)
@Ok("json")
@Fail("json")
@IocBy(args = {
	"*js", "ioc/", "*anno", "net.wendal.nutzbook", "*async", "*tx"
})
public class MainModule {

	@At("/hello")
	@Ok("jsp:jsp.hello")
	public String doHello(){
		return "hello";
	}
}

userModeule:

package com.cdroid.nutz.module;

import java.util.Date;

import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;

@IocBean
public class UserModule {
	
	private static final Log log = Logs.get();
	
	@Inject
	private Dao dao;
	
	@At("/ping")
	public Object ping(){
		log.debug("dao == " + dao);
		return new Date();
	}
}

启动日志:

[INFO ] 11:13:21.554 org.nutz.mvc.NutFilter._init(NutFilter.java:81) - NutFilter[nutz] starting ...
[DEBUG] 11:13:21.686 org.nutz.resource.Scans.<init>(Scans.java:509) - Locations for Scans:
[Dir[path=D:\dev\eclipse], Jar[path=D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\lib\nutz-1.r.60.jar], Dir[path=D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\classes], Jar[path=D:\dev\apache-tomcat-7.0.50\bin\bootstrap.jar], Jar[path=D:\dev\apache-tomcat-7.0.50\bin\tomcat-juli.jar], Jar[path=C:\Program Files\Java\jdk1.7.0_75\lib\tools.jar]]
[DEBUG] 11:13:21.793 org.nutz.resource.Scans.init(Scans.java:105) - Locations for Scans:
{D:\dev\eclipse=Dir[path=D:\dev\eclipse], D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\lib\nutz-1.r.60.jar=Jar[path=D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\lib\nutz-1.r.60.jar], D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\classes=Dir[path=D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\classes], D:\dev\apache-tomcat-7.0.50\bin\bootstrap.jar=Jar[path=D:\dev\apache-tomcat-7.0.50\bin\bootstrap.jar], D:\dev\apache-tomcat-7.0.50\bin\tomcat-juli.jar=Jar[path=D:\dev\apache-tomcat-7.0.50\bin\tomcat-juli.jar], C:\Program Files\Java\jdk1.7.0_75\lib\tools.jar=Jar[path=C:\Program Files\Java\jdk1.7.0_75\lib\tools.jar], D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\lib\javax.servlet-api-3.1.0.jar=Jar[path=D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\lib\javax.servlet-api-3.1.0.jar], D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\lib\log4j-1.2.17.jar=Jar[path=D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\lib\log4j-1.2.17.jar], D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\lib\druid-1.0.27.jar=Jar[path=D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\lib\druid-1.0.27.jar], D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\lib\junit-3.8.1.jar=Jar[path=D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\lib\junit-3.8.1.jar], D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\lib\mysql-connector-java-6.0.5.jar=Jar[path=D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\nutz\WEB-INF\lib\mysql-connector-java-6.0.5.jar]}
[DEBUG] 11:13:21.850 org.nutz.castor.Castors.reload(Castors.java:115) - Using 95 castor for Castors
[DEBUG] 11:13:21.867 org.nutz.mvc.config.AbstractNutConfig.createLoading(AbstractNutConfig.java:59) - Loading by class org.nutz.mvc.impl.NutLoading
[INFO ] 11:13:21.870 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:55) - Nutz Version : 1.r.60 
[INFO ] 11:13:21.870 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:56) - Nutz.Mvc[nutz] is initializing ...
[DEBUG] 11:13:21.871 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:60) - Web Container Information:
[DEBUG] 11:13:21.872 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:61) -  - Default Charset : UTF-8
[DEBUG] 11:13:21.873 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:62) -  - Current . path  : D:\dev\eclipse\.
[DEBUG] 11:13:21.873 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:63) -  - Java Version    : 1.7.0_75
[DEBUG] 11:13:21.873 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:64) -  - File separator  : \
[DEBUG] 11:13:21.873 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:65) -  - Timezone        : Asia/Shanghai
[DEBUG] 11:13:21.874 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:66) -  - OS              : Windows 7 amd64
[DEBUG] 11:13:21.874 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:67) -  - ServerInfo      : Apache Tomcat/7.0.50
[DEBUG] 11:13:21.874 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:68) -  - Servlet API     : 3.0
[DEBUG] 11:13:21.875 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:73) -  - ContextPath     : /nutz
[DEBUG] 11:13:21.875 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:74) -  - context.tempdir : D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\work\Catalina\localhost\nutz
[DEBUG] 11:13:21.875 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:75) -  - MainModule      : com.cdroid.nutz.MainModule
[DEBUG] 11:13:21.876 org.nutz.mvc.impl.NutLoading.createContext(NutLoading.java:238) - >> app.root = D:/dev/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp3/wtpwebapps/nutz
[DEBUG] 11:13:21.879 org.nutz.mvc.impl.NutLoading.createIoc(NutLoading.java:379) - @IocBy(type=org.nutz.mvc.ioc.provider.ComboIocProvider, args=["*js", "ioc/", "*anno", "net.wendal.nutzbook", "*async", "*tx"],init=[])
[DEBUG] 11:13:21.901 org.nutz.resource.Scans.scan(Scans.java:274) - Found 1 resource by src( ioc/ ) , regex( ^(.+[.])(js|json)$ )
[DEBUG] 11:13:21.901 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:48) - loading ioc js config from [dao.js]
[DEBUG] 11:13:21.904 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:56) - Loaded 2 bean define from path=[ioc/] --> [dataSource, dao]
[DEBUG] 11:13:21.907 org.nutz.resource.Scans.scan(Scans.java:274) - Found 0 resource by src( net/wendal/nutzbook/ ) , regex( ^.+[.]class$ )
[WARN ] 11:13:21.908 org.nutz.ioc.loader.annotation.AnnotationIocLoader.<init>(AnnotationIocLoader.java:55) - NONE Annotation-Class found!! Check your ioc configure!! packages=[net.wendal.nutzbook]
[DEBUG] 11:13:21.910 org.nutz.ioc.aop.SimpleAopMaker.<init>(SimpleAopMaker.java:79) - Load AopConfigure for anno=org.nutz.aop.interceptor.async.Async by type=org.nutz.aop.interceptor.async.AsyncAopIocLoader
[DEBUG] 11:13:21.912 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:40) - Loaded 5 bean define from reader --
[txREPEATABLE_READ, txREAD_COMMITTED, txNONE, txSERIALIZABLE, txREAD_UNCOMMITTED]
[INFO ] 11:13:21.915 org.nutz.ioc.impl.NutIoc.<init>(NutIoc.java:98) - NutIoc init begin ...
[INFO ] 11:13:21.918 org.nutz.ioc.impl.NutIoc.<init>(NutIoc.java:115) - ... NutIoc init complete
[INFO ] 11:13:21.921 org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:159) - Build URL mapping by org.nutz.mvc.impl.UrlMappingImpl ...
[DEBUG] 11:13:21.923 org.nutz.mvc.impl.NutLoading.createViewMakers(NutLoading.java:369) - @Views(DefaultViewMaker.class)
[DEBUG] 11:13:21.930 org.nutz.mvc.impl.NutLoading.createChainMaker(NutLoading.java:266) - @ChainBy(org.nutz.mvc.impl.NutActionChainMaker)
[DEBUG] 11:13:21.937 org.nutz.mvc.impl.Loadings.scanModules(Loadings.java:154) - module class location 'file:/D:/dev/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp3/wtpwebapps/nutz/WEB-INF/classes/com/cdroid/nutz/MainModule.class'
[DEBUG] 11:13:21.937 org.nutz.mvc.impl.Loadings.scanModuleInPackage(Loadings.java:184) -  > scan 'com.cdroid.nutz'
[DEBUG] 11:13:21.939 org.nutz.resource.Scans.scan(Scans.java:274) - Found 3 resource by src( com/cdroid/nutz/ ) , regex( ^.+[.]class$ )
[DEBUG] 11:13:21.945 org.nutz.mvc.impl.Loadings.checkModule(Loadings.java:198) -    >> add 'com.cdroid.nutz.MainModule'
[DEBUG] 11:13:21.948 org.nutz.mvc.impl.Loadings.checkModule(Loadings.java:198) -    >> add 'com.cdroid.nutz.module.UserModule'
[INFO ] 11:13:21.953 org.nutz.mvc.impl.processor.ModuleProcessor.init(ModuleProcessor.java:61) - Create Module obj without Ioc --> class com.cdroid.nutz.MainModule
[INFO ] 11:13:21.954 org.nutz.mvc.impl.NutActionChainMaker.getProcessorByName(NutActionChainMaker.java:72) - Optional processor class not found, disabled : org.nutz.integration.shiro.NutShiroProcessor
[INFO ] 11:13:21.957 org.nutz.mvc.impl.NutActionChainMaker.getProcessorByName(NutActionChainMaker.java:72) - Optional processor class not found, disabled : org.nutz.plugins.validation.ValidationProcessor
[DEBUG] 11:13:21.966 org.nutz.mvc.impl.UrlMappingImpl.print(UrlMappingImpl.java:146) -    '/hello'                    >> (MainModule.java:21).doHello          : String     | @Ok(jsp:jsp.hello) @Fail(json ) | by 0 Filters | (I:UTF-8/O:UTF-8)
[WARN ] 11:13:21.969 org.nutz.mvc.impl.processor.ModuleProcessor.init(ModuleProcessor.java:77) - Moudle with @InjectName('userModule') or @IocBean('userModule') but no such ioc bean found!! Pls check your ioc configure!!
[DEBUG] 11:13:21.970 org.nutz.mvc.impl.UrlMappingImpl.print(UrlMappingImpl.java:146) -    '/ping'                     >> (UserModule.java:22).ping             : Object     | @Ok(json ) @Fail(json ) | by 0 Filters | (I:UTF-8/O:UTF-8)
[INFO ] 11:13:21.970 org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:220) - Found 2 module methods
[DEBUG] 11:13:21.971 org.nutz.mvc.impl.NutLoading.evalLocalization(NutLoading.java:334) - @Localization not define
[INFO ] 11:13:21.972 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:141) - Nutz.Mvc[nutz] is up in 96ms

然后我访问 userModule的ping方法:http://localhost:8080/nutz/ping

[DEBUG] 11:14:14.266 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [GET] path=/ping : UserModule.ping(UserModule.java:22)
[DEBUG] 11:14:14.269 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'userModule'<class com.cdroid.nutz.module.UserModule>
[DEBUG] 11:14:14.270 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get '$aop_async'<interface org.nutz.ioc.aop.config.AopConfigration>
[DEBUG] 11:14:14.271 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) - 	 >> Load definition name=$aop_async
[DEBUG] 11:14:14.278 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) - Found IocObject($aop_async) in AsyncAopIocLoader@122288937
[DEBUG] 11:14:14.279 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) - 	 >> Make...'$aop_async'<interface org.nutz.ioc.aop.config.AopConfigration>
[DEBUG] 11:14:14.281 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) - Save object '$aop_async' to [app] 
[DEBUG] 11:14:14.285 org.nutz.ioc.aop.SimpleAopMaker.<init>(SimpleAopMaker.java:79) - Load AopConfigure for anno=org.nutz.ioc.aop.Aop by type=org.nutz.ioc.aop.config.impl.AnnotationAopConfigration
[DEBUG] 11:14:14.285 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) - 	 >> Load definition name=userModule
[WARN ] 11:14:14.286 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) - Error@/ping :
org.nutz.ioc.IocException: [userModule] # For object [userModule] - type:[class com.cdroid.nutz.module.UserModule]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
	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:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1721)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1679)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.ioc.ObjectLoadException: Object 'userModule' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:174)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
	... 27 more

求大神帮帮忙啊

4 回复

net.wendal.nutzbook 改一下哦

@wendal 原来这个路径是scanpackage module的路径啊。。

mainModules 配置modules(scanPackage = true) 不是就会自动扫面当前目录下的子目录了吗??

@chafferer 报的是ioc错误哦

@wendal 嗯是的,那我把路径改成我自己的就可以了。
我是想问,如果没写那个路径的话,modules 会不会自动扫描自己所在目录所在的子目录呢?
我刚才把那句话删掉就不行了

添加回复
请先登陆
回到顶部