NutzCN Logo
问答 初次学nutz框架,一步步跟着搭建的过程中,遇到了以下问题,求大牛们指点
发布于 136天前 作者 qq_b61182f1 253 次浏览 复制 上一个帖子 下一个帖子
标签: nutzbook

UserModule类

package net.wendal.nutzbook.module;

import net.wendal.nutzbook.bean.User;

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;

@IocBean
@At("/user")
@Ok("json")
@Fail("http:500")
public class UserModule {

	@Inject
	protected Dao dao;
	
	@At
	public int count(){
		return dao.count(User.class);
	}
}

dao.js文件内容如下:

var ioc = {
		dataSource : {
			type : "com.alibaba.druid.pool.DruidDataSource",
			events : {
				create : "init",
				depose : "close"
			},
			fields : {
				url : "jdbc:mysql://192.168.8.220:3306/nutzbook",
				username : "root",
				password : "",
				testWhileIdle : true,
				validationQuery : "select 1",
				maxActive : 100
			}
		},
		dao : {
			type : "org.nutz.dao.impl.NutDao",
			args : [{refer:"dataSource"}]
		}
};

MainModule类代码如下:

package net.wendal.nutzbook;

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;

@SetupBy(value=MainSetup.class)
@IocBy(type=ComboIocProvider.class, args={"*js","ioc/","*anno","net.wendal.nutzbook","*tx"})
@Modules(scanPackage=true)
public class MainModule {

}

MainSetup类代码如下:

package net.wendal.nutzbook;

import java.util.Date;

import net.wendal.nutzbook.bean.User;

import org.nutz.dao.Dao;
import org.nutz.dao.util.Daos;
import org.nutz.ioc.Ioc;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;

public class MainSetup implements Setup{

	@Override
	public void destroy(NutConfig config) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void init(NutConfig config) {
		// TODO Auto-generated method stub
		Ioc ioc = config.getIoc();
		Dao dao = ioc.get(Dao.class);
		Daos.createTablesInPackage(dao, "net.wendal.nutzbook", false);
		
		//初始化默认根用户
		if (dao.count(User.class)==0){
			User user = new User();
			user.setName("admin");
			user.setPassword("123456");
			user.setCreateTime(new Date());
			user.setUpdateTime(new Date());
			dao.insert(user);
		}
		
	}

}

User类的代码如下:

package net.wendal.nutzbook.bean;

import java.util.Date;

import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Name;
import org.nutz.dao.entity.annotation.Table;

@Table("t_user")
public class User {
	@Id
	private int id;
	@Name
	@Column
	private String name;
	@Column("passwd")
	private String password;
	@Column
	private String salt;
	@Column("ct")
	private Date createTime;
	@Column("ut")
	private Date updateTime;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getSalt() {
		return salt;
	}
	public void setSalt(String salt) {
		this.salt = salt;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public Date getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	
	
}

web.xml代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>nutzbook</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  <filter>
  		<filter-name>nutz</filter-name>
  		<filter-class>org.nutz.mvc.NutFilter</filter-class>
  		<init-param>
  			<param-name>modules</param-name>
  			<param-value>net.wendal.nutzbook.MainModule</param-value>
  		</init-param>
  </filter>
  
  <filter-mapping>
  		<filter-name>nutz</filter-name>
  		<url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

jar包已加入classpath,大牛们,我是跟着一步步过来的,初始化的时候能插入admin用户记录到t_user表(表服务器启动的时候自动生成了)。

26 回复

关键是你有那些问题呢?报的错在那里?

@qq_ce28126d 2016-10-9 15:24:24.351 DEBUG [http-8080-1] Search mapping for path=/user/count : NOT Action match

@qq_ce28126d 访问http://127.0.0.1:8080/nutzbook/user/count地址报的错,我找了好久,貌似没有错,我是跟着文档一步步过来的

UserModule上的ok和fail标签 移动到方法上面去。

贴完整启动日志.

是否根据文档中的如下描述检查了一下呢?

可能出现的问题:

Search mapping for path=/user/count : NOT Action match
找不到方法, 一般是@At写错或者UserModule的package写错,导致映射不到或者根本没找到这个类

@qq_1dd23c23哪里有@GET,手册上没这个啊

@tangshaobo 移到方法上去???,文档上是放在类上面的啊

@qq_1dd23c23 检查了呀,就是因为没有找到错误,所以。。。。

你还是按照wendal的建议:贴完整启动日志.

服务器启动没有错,日志信息如下,纳闷,真奇怪,为什么提示 NOT Action match错误呢?

十月 09, 2016 3:38:11 下午 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jdk1.7.0_13\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jdk1.7.0_13/bin/../jre/bin/client;C:/Program Files (x86)/Java/jdk1.7.0_13/bin/../jre/bin;C:/Program Files (x86)/Java/jdk1.7.0_13/bin/../jre/lib/i386;C:\Program Files (x86)\Java\jdk1.7.0_13\bin;E:\work\apache-maven-3.3.9-bin\apache-maven-3.3.9\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\IDM Computer Solutions\UltraEdit;C:\Users\yangfeng\Downloads\apache-cxf-3.1.7\bin;;E:\work\eclipse;;.
十月 09, 2016 3:38:12 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:nutzbook' did not find a matching property.
十月 09, 2016 3:38:12 下午 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
十月 09, 2016 3:38:12 下午 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 271 ms
十月 09, 2016 3:38:12 下午 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
十月 09, 2016 3:38:12 下午 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.44
2016-10-9 15:38:12.312 WARN [main] !!You are using default SystemLog! Don't use it in Production environment!!
2016-10-9 15:38:12.317 INFO [main] NutFilter[nutz] starting ...
2016-10-9 15:38:12.459 DEBUG [main] Locations for Scans:
[Dir[path=E:\work\eclipse], Jar[path=D:\hbk\wlkj\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\nutzbook\WEB-INF\lib\nutz-1.r.58.jar], Jar[path=E:\work\apache-tomcat-6.0.44\bin\bootstrap.jar], Jar[path=C:\Program Files (x86)\Java\jdk1.7.0_13\lib\tools.jar]]
2016-10-9 15:38:12.513 DEBUG [main] Locations for Scans:
{E:\work\eclipse=Dir[path=E:\work\eclipse], D:\hbk\wlkj\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\nutzbook\WEB-INF\lib\nutz-1.r.58.jar=Jar[path=D:\hbk\wlkj\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\nutzbook\WEB-INF\lib\nutz-1.r.58.jar], E:\work\apache-tomcat-6.0.44\bin\bootstrap.jar=Jar[path=E:\work\apache-tomcat-6.0.44\bin\bootstrap.jar], C:\Program Files (x86)\Java\jdk1.7.0_13\lib\tools.jar=Jar[path=C:\Program Files (x86)\Java\jdk1.7.0_13\lib\tools.jar], D:\hbk\wlkj\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\nutzbook\WEB-INF\classes=Dir[path=D:\hbk\wlkj\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\nutzbook\WEB-INF\classes], D:\hbk\wlkj\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\nutzbook\WEB-INF\lib\druid-0.2.6.jar=Jar[path=D:\hbk\wlkj\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\nutzbook\WEB-INF\lib\druid-0.2.6.jar], D:\hbk\wlkj\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\nutzbook\WEB-INF\lib\mysql-connector-java-5.1.20-bin.jar=Jar[path=D:\hbk\wlkj\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\nutzbook\WEB-INF\lib\mysql-connector-java-5.1.20-bin.jar]}
2016-10-9 15:38:12.560 DEBUG [main] Using 94 castor for Castors
2016-10-9 15:38:12.573 DEBUG [main] Loading by class org.nutz.mvc.impl.NutLoading
2016-10-9 15:38:12.575 INFO [main] Nutz Version : 1.r.58 
2016-10-9 15:38:12.575 INFO [main] Nutz.Mvc[nutz] is initializing ...
2016-10-9 15:38:12.575 DEBUG [main] Web Container Information:
2016-10-9 15:38:12.576 DEBUG [main]  - Default Charset : UTF-8
2016-10-9 15:38:12.576 DEBUG [main]  - Current . path  : E:\work\eclipse\.
2016-10-9 15:38:12.577 DEBUG [main]  - Java Version    : 1.7.0_13
2016-10-9 15:38:12.577 DEBUG [main]  - File separator  : \
2016-10-9 15:38:12.577 DEBUG [main]  - Timezone        : Asia/Shanghai
2016-10-9 15:38:12.577 DEBUG [main]  - OS              : Windows 7 x86
2016-10-9 15:38:12.577 DEBUG [main]  - ServerInfo      : Apache Tomcat/6.0.44
2016-10-9 15:38:12.578 DEBUG [main]  - Servlet API     : 2.5
2016-10-9 15:38:12.578 DEBUG [main]  - ContextPath     : /nutzbook
2016-10-9 15:38:12.578 DEBUG [main]  - context.tempdir : D:\hbk\wlkj\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\nutzbook
2016-10-9 15:38:12.578 DEBUG [main]  - MainModule      : net.wendal.nutzbook.MainModule
2016-10-9 15:38:12.579 DEBUG [main] >> app.root = D:/hbk/wlkj/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/nutzbook
2016-10-9 15:38:12.582 DEBUG [main] @IocBy(type=org.nutz.mvc.ioc.provider.ComboIocProvider, args=["*js", "ioc/", "*anno", "net.wendal.nutzbook", "*tx"],init=[])
2016-10-9 15:38:12.598 DEBUG [main] Found 1 resource by src( ioc/ ) , regex( ^(.+[.])(js|json)$ )
2016-10-9 15:38:12.598 DEBUG [main] loading ioc js config from [dao.js]
2016-10-9 15:38:12.602 DEBUG [main] Loaded 2 bean define from path=[ioc/] --> [dataSource, dao]
2016-10-9 15:38:12.604 DEBUG [main] Found 3 resource by src( net/wendal/nutzbook/ ) , regex( ^.+[.]class$ )
2016-10-9 15:38:12.612 WARN [main] NONE Annotation-Class found!! Check your ioc configure!! packages=[net.wendal.nutzbook]
2016-10-9 15:38:12.612 DEBUG [main] Loaded 5 bean define from reader --
[txREPEATABLE_READ, txREAD_COMMITTED, txNONE, txSERIALIZABLE, txREAD_UNCOMMITTED]
2016-10-9 15:38:12.615 INFO [main] NutIoc init begin ...
2016-10-9 15:38:12.617 INFO [main] ... NutIoc init complete
2016-10-9 15:38:12.620 INFO [main] Build URL mapping by org.nutz.mvc.impl.UrlMappingImpl ...
2016-10-9 15:38:12.621 DEBUG [main] @Views(DefaultViewMaker.class)
2016-10-9 15:38:12.625 DEBUG [main] @ChainBy(org.nutz.mvc.impl.NutActionChainMaker)
2016-10-9 15:38:12.635 DEBUG [main] module class location 'file:/D:/hbk/wlkj/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/nutzbook/WEB-INF/classes/net/wendal/nutzbook/MainModule.class'
2016-10-9 15:38:12.636 DEBUG [main]  > scan 'net.wendal.nutzbook'
2016-10-9 15:38:12.637 DEBUG [main] Found 3 resource by src( net/wendal/nutzbook/ ) , regex( ^.+[.]class$ )
2016-10-9 15:38:12.638 WARN [main] None module classes found!!!
2016-10-9 15:38:12.638 WARN [main] None @At found in any modules class!!
2016-10-9 15:38:12.639 DEBUG [main] @Localization not define
2016-10-9 15:38:12.639 INFO [main] Setup application...
2016-10-9 15:38:12.640 DEBUG [main] Get 'dao'<interface org.nutz.dao.Dao>
2016-10-9 15:38:12.641 DEBUG [main] Load AopConfigure for anno=org.nutz.ioc.aop.Aop by type=org.nutz.ioc.aop.config.impl.AnnotationAopConfigration
2016-10-9 15:38:12.642 DEBUG [main] 	 >> Load definition name=dao
2016-10-9 15:38:12.643 DEBUG [main] Loading define for name=dao
2016-10-9 15:38:12.647 DEBUG [main] Found IocObject(dao) in JsonLoader(paths=[ioc/])
2016-10-9 15:38:12.647 DEBUG [main] 	 >> Make...'dao'<interface org.nutz.dao.Dao>
2016-10-9 15:38:12.658 DEBUG [main] Load class org.nutz.dao.impl.NutDao without AOP
2016-10-9 15:38:12.659 DEBUG [main] Save object 'dao' to [app] 
2016-10-9 15:38:12.660 DEBUG [main] Get 'dataSource'<>
2016-10-9 15:38:12.660 DEBUG [main] 	 >> Load definition name=dataSource
2016-10-9 15:38:12.660 DEBUG [main] Loading define for name=dataSource
2016-10-9 15:38:12.667 DEBUG [main] Found IocObject(dataSource) in JsonLoader(paths=[ioc/])
2016-10-9 15:38:12.668 DEBUG [main] 	 >> Make...'dataSource'<>
2016-10-9 15:38:12.677 DEBUG [main] Load class com.alibaba.druid.pool.DruidDataSource without AOP
2016-10-9 15:38:12.677 DEBUG [main] Save object 'dataSource' to [app] 
十月 09, 2016 3:38:12 下午 com.alibaba.druid.pool.DruidDataSource info
INFO: {dataSource-1} inited
2016-10-9 15:38:12.714 DEBUG [main] Get 'dataSource'<>
2016-10-9 15:38:12.720 DEBUG [main] NutDao[_selfId=0] init ...
2016-10-9 15:38:12.738 INFO [main] Init file-pool by: C:\Users\yangfeng/.nutz/tmp/dao/ [200000]
2016-10-9 15:38:12.739 DEBUG [main] file-pool.home: 'C:\Users\yangfeng\.nutz\tmp\dao'
2016-10-9 15:38:12.740 INFO [main] file-pool.cursor: 0
2016-10-9 15:38:12.745 DEBUG [main] Jdbcs init complete
2016-10-9 15:38:12.746 INFO [main] Get Connection from DataSource for JdbcExpert, if I lock at here, check your database server and configure
2016-10-9 15:38:12.913 DEBUG [main] JDBC Driver --> mysql-connector-java-5.1.20 ( Revision: tonci.grgin@oracle.com-20111003110438-qfydx066wsbydkbw )
2016-10-9 15:38:12.913 DEBUG [main] JDBC Name   --> MySQL-AB JDBC Driver
2016-10-9 15:38:12.913 DEBUG [main] JDBC URL    --> jdbc:mysql://192.168.8.220:3306/nutzbook
2016-10-9 15:38:12.919 DEBUG [main] Mysql : character_set_client=utf8mb4
2016-10-9 15:38:12.919 DEBUG [main] Mysql : character_set_connection=utf8mb4
2016-10-9 15:38:12.919 DEBUG [main] Mysql : character_set_database=utf8
2016-10-9 15:38:12.920 DEBUG [main] Mysql : character_set_filesystem=binary
2016-10-9 15:38:12.920 DEBUG [main] Mysql : character_set_results=
2016-10-9 15:38:12.920 DEBUG [main] Mysql : character_set_server=utf8
2016-10-9 15:38:12.920 DEBUG [main] Mysql : character_set_system=utf8
2016-10-9 15:38:12.921 DEBUG [main] Mysql : character_sets_dir=/usr/local/mysql/share/charsets/
2016-10-9 15:38:12.922 DEBUG [main] Mysql : database=nutzbook
2016-10-9 15:38:12.923 DEBUG [main] Mysql : user=root@192.168.8.133
2016-10-9 15:38:12.935 DEBUG [main] Database info --> MYSQL:[MySQL - 5.5.27-log]
2016-10-9 15:38:12.939 DEBUG [main] Found 3 resource by src( net/wendal/nutzbook/ ) , regex( ^.+[.]class$ )
2016-10-9 15:38:13.15 DEBUG [main] SELECT COUNT(*) FROM t_user 
2016-10-9 15:38:13.17 INFO [main] Nutz.Mvc[nutz] is up in 438ms
十月 09, 2016 3:38:13 下午 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
十月 09, 2016 3:38:13 下午 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
十月 09, 2016 3:38:13 下午 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/12  config=null
十月 09, 2016 3:38:13 下午 org.apache.catalina.startup.Catalina start
INFO: Server startup in 925 ms

@wendal 启动信息在下面

@qq_1dd23c23 已贴

None module classes found!!!
----不知道是不是这里出问题了呀

2016-10-9 15:38:12.636 DEBUG [main]  > scan 'net.wendal.nutzbook'
2016-10-9 15:38:12.637 DEBUG [main] Found 3 resource by src( net/wendal/nutzbook/ ) , regex( ^.+[.]class$ )
2016-10-9 15:38:12.638 WARN [main] None module classes found!!!
2016-10-9 15:38:12.638 WARN [main] None @At found in any modules class!!

UserModule没编译过去.

日志显示只找到了3个类, MainModule,MainSetup和User类. UserModule这个类,无论是ioc和@At的扫描,均没有找到它.

@wendal 这个是什么问题呢?是因为不是的classes没有,新建动态web工程的时候,我设置了output是WebContent/WEB-INF/classes下面的,我查看了下工程目录,在WebContent/WEB-INF/classes/net/wendal/nutzbook 下只有一个bean文件夹,和MainModule.class 和 MainSetup.class

clean and build

@wendal 那怎么解决呢,为什么找不到呢,好想截eclipse的项目架构图的,可惜截图不了

eclipse的Project菜单里面的Clean按钮, 及检查一下Build automatically 是否打钩了.

@wendal 已经解决问题,谢谢各位

@qq_b61182f1 原因是什么?

@wendal 我把classes目录删除后,重启一直报错,说找不到类,我部署到另一个tomcat(版本7),结果就好了,应该是之前tomcat服务器的原因吧,自己也不是很清楚原因,换了一个tomcat就好了

@wendal 以正确的用户名和密码点击登录按钮,经过后台处理返回true,然后能弹出登录成功提示,但一直还是停留在登录页面,代码中的return fasle是干嘛的,正常流程应该是登录成功显示后面的用户id信息和退出按钮啊,
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



Insert title here


var me ='<%=session.getAttribute("me")%>';
var base='${base}';
$(function(){
$("#login_button").click(function(){
$.ajax({
url:base+'/user/login',
data:$("#loginForm").serialize(),
type:"post",
dataType:'json',
error:function(){
alert("connection error");
},
success:function(data){
if(data==true){
alert("登录成功");
}else{
alert("用户名或密码错误");
}
}
});
return false;
});

    if(me!="null"){
       $("#login_div").hide();
       $("#userinfo").text("你的id是"+me);
       $("#user_info_div").show();
    }else{
       $("#login_div").show();
       $("#user_info_div").hide();
    }
});





用户名:
密码:
登录


@qq_b61182f1 哦,知道了,一定要加location.reload();

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