1、首先配置Web.xml,配置Nutz的主模块。
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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
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>TestIocAnnotation</display-name>
<filter>
<filter-name>nutz</filter-name>
<filter-class>org.nutz.mvc.NutFilter</filter-class>
<init-param>
<param-name>modules</param-name>
<param-value>demo.nutz.setup.MainModule</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>nutz</filter-name>
<url-pattern>*.shtml</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
2、创建主模块类MainModule.java
Java代码 收藏代码
package demo.nutz.setup;
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 demo.nutz.action.ArticleInfoAction;
/**
* 主模块
*
* @author gevin(gevinhjy@foxmail.com)
*
*/
@Modules(value = ArticleInfoAction.class, scanPackage = true)
@IocBy(type = ComboIocProvider.class, args = {
"*org.nutz.ioc.loader.json.JsonLoader", "ioc/dao.js",
"*org.nutz.ioc.loader.annotation.AnnotationIocLoader", "demo.nutz"})
@SetupBy(NutzSetup.class)
public class MainModule {
}