change: 每个starter应该独占一个package

add: 新增jedis,quartz的starter
add: redis的demo
This commit is contained in:
Wendal Chen 2017-11-14 14:29:26 +08:00
parent 81a16a1ee3
commit cefc02304a
31 changed files with 252 additions and 40 deletions

View File

@ -30,10 +30,10 @@ public class MainLauncher {
- [ ] 基础框架
- [ ] 基础框架的文档
- [ ] 基本框架的实现
- [x] 基本框架的实现
- [ ] 服务器类启动器
- [ ] web类启动器
- [ ] Jetty
- [x] Jetty
- [ ] Tomcat
- [ ] Undertow
- [ ] 非Web类启动器
@ -47,10 +47,10 @@ public class MainLauncher {
- [ ] ZBus
- [ ] 数据库类相关
- [ ] 关系型数据库
- [ ] Jdbc连接池
- [ ] Nutz.Dao
- [x] Jdbc连接池
- [x] Nutz.Dao
- [ ] 非关系型数据库
- [ ] Redis
- [x] Redis
- [ ] MongoDB
- [ ] neo4j
- [ ] memcached
@ -80,6 +80,8 @@ public class MainLauncher {
- [ ] 规则引擎
- [ ] urule
- [ ] drools
- [ ] 开放平台
- [x] 微信公众号开放平台
- [ ] 云平台
- [ ] 阿里云
- [ ] 腾讯云

View File

@ -0,0 +1,42 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-demo</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>nutzboot-demo-simple-redis</artifactId>
<dependencies>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-nutz</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-jetty</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-jedis</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,39 @@
package io.nutz.demo.simple;
import static org.nutz.integration.jedis.RedisInterceptor.jedis;
import org.nutz.boot.NbApp;
import org.nutz.dao.Dao;
import org.nutz.ioc.aop.Aop;
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;
import org.nutz.mvc.annotation.Ok;
@IocBean(create="init")
public class MainLauncher {
private static final Log log = Logs.get();
@Inject
Dao dao;
@Ok("raw")
@At("/redis/info")
@Aop("redis")
public String info() {
return jedis().info();
}
@Aop("redis")
public void init() {
log.info(jedis().ping());
}
public static void main(String[] args) throws Exception {
new NbApp(MainLauncher.class).run();
}
}

View File

@ -0,0 +1,7 @@
jetty.port=8080
jetty.host=127.0.0.1
jdbc.type=druid
jdbc.url=jdbc:h2:mem:~
jdbc.driverClassName=org.h2.Driver

View File

@ -0,0 +1,7 @@
log4j.rootLogger=debug,Console
log4j.logger.org.eclipse.jetty=info
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%-5p] %d{HH:mm:ss.SSS} %l - %m%n

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello, So NB!</title>
</head>
<body>
Hello, So NB!
</body>
</html>

View File

@ -8,9 +8,10 @@
<artifactId>nutzboot-demo</artifactId>
<packaging>pom</packaging>
<modules>
<module>nutzboot-demo-maker</module>
<module>nutzboot-demo-simple</module>
<module>nutzboot-demo-simple-dao</module>
<module>nutzboot-demo-maker</module>
<module>nutzboot-demo-simple-redis</module>
</modules>
<properties>
</properties>

View File

@ -1,4 +1,4 @@
package org.nutz.boot.starter;
package org.nutz.boot.starter.jdbc;
import java.util.HashMap;
import java.util.Map;
@ -8,12 +8,14 @@ import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.nutz.dao.impl.SimpleDataSource;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Lang;
import org.nutz.lang.Strings;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
@IocBean
@ -24,7 +26,9 @@ public class DataSourceStarter {
@Inject
protected PropertiesProxy conf;
@SuppressWarnings({"rawtypes", "unchecked"})
@Inject("refer:$ioc")
protected Ioc ioc;
@IocBean
public DataSource getDataSource() throws Exception {
switch (conf.get(PRE+"type", "simple")) {
@ -41,11 +45,7 @@ public class DataSourceStarter {
return simpleDataSource;
case "druid":
case "com.alibaba.druid.pool.DruidDataSource":
if (Strings.isBlank(conf.get(PRE+"url"))) {
throw new RuntimeException("need jdbc.url");
}
Map map = Lang.filter(new HashMap(conf.toMap()), PRE, null, null, null);
return DruidDataSourceFactory.createDataSource(map);
return ioc.get(DruidDataSource.class);
case "jndi":
return (DataSource) ((Context)new InitialContext().lookup("java:comp/env")).lookup(conf.check(PRE+"value"));
// TODO 支持其他数据源
@ -54,4 +54,14 @@ public class DataSourceStarter {
}
throw new RuntimeException("not support nutz.dataSource.type=" + conf.get("jdbc.type"));
}
@SuppressWarnings({"rawtypes", "unchecked"})
@IocBean(name="druidDataSource", depose="close")
public DruidDataSource createDruidDataSource() throws Exception {
if (Strings.isBlank(conf.get(PRE+"url"))) {
throw new RuntimeException("need jdbc.url");
}
Map map = Lang.filter(new HashMap(conf.toMap()), PRE, null, null, null);
return (DruidDataSource) DruidDataSourceFactory.createDataSource(map);
}
}

View File

@ -1 +1 @@
org.nutz.boot.starter.DataSourceStarter
org.nutz.boot.starter.jdbc.DataSourceStarter

View File

@ -6,4 +6,21 @@
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>nutzboot-starter-jedis</artifactId>
<dependencies>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutz-integration-jedis</artifactId>
<version>1.r.63-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,14 @@
package org.nutz.boot.starter.jedis;
import org.nutz.boot.ioc.IocLoaderProvider;
import org.nutz.integration.jedis.JedisIocLoader;
import org.nutz.ioc.IocLoader;
import org.nutz.ioc.loader.annotation.IocBean;
@IocBean
public class JedisStarter implements IocLoaderProvider {
public IocLoader getIocLoader() {
return new JedisIocLoader();
}
}

View File

@ -0,0 +1 @@
org.nutz.boot.starter.jedis.JedisStarter

View File

@ -22,6 +22,7 @@ import org.nutz.boot.aware.AppContextAware;
import org.nutz.boot.aware.ClassLoaderAware;
import org.nutz.boot.aware.IocAware;
import org.nutz.boot.starter.ServerFace;
import org.nutz.boot.starter.WebEventListenerFace;
import org.nutz.boot.starter.WebFilterFace;
import org.nutz.boot.starter.WebServletFace;
import org.nutz.ioc.Ioc;
@ -134,6 +135,10 @@ public class JettyStarter implements ClassLoaderAware, IocAware, ServerFace, Lif
holder.setInitParameters(webServlet.getInitParameters());
wac.addServlet(holder, webServlet.getPathSpec());
}
if (object instanceof WebEventListenerFace) {
WebEventListenerFace contextListener = (WebEventListenerFace)object;
wac.addEventListener(contextListener.getEventListener());
}
}
}

View File

@ -1,4 +1,4 @@
package org.nutz.boot.starter;
package org.nutz.boot.starter.nutz.dao;
import javax.sql.DataSource;

View File

@ -1 +1 @@
org.nutz.boot.starter.NutDaoStarter
org.nutz.boot.starter.nutz.dao.NutDaoStarter

View File

@ -1,4 +1,4 @@
package org.nutz.boot.starter;
package org.nutz.boot.starter.nutz.mvc;
import org.nutz.mvc.annotation.LoadingBy;
import org.nutz.mvc.annotation.Localization;

View File

@ -1,4 +1,4 @@
package org.nutz.boot.starter;
package org.nutz.boot.starter.nutz.mvc;
import org.nutz.boot.AppContext;
import org.nutz.ioc.Ioc;

View File

@ -1,4 +1,4 @@
package org.nutz.boot.starter;
package org.nutz.boot.starter.nutz.mvc;
import java.util.EnumSet;
import java.util.HashMap;
@ -7,6 +7,7 @@ import java.util.Map;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import org.nutz.boot.starter.WebFilterFace;
import org.nutz.ioc.Ioc;
import org.nutz.mvc.NutFilter;

View File

@ -1 +1 @@
org.nutz.boot.starter.NutFilterStarter
org.nutz.boot.starter.nutz.mvc.NutFilterStarter

View File

@ -0,0 +1,32 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-parent</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>nutzboot-starter-quartz</artifactId>
<dependencies>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutz-integration-quartz</artifactId>
<version>1.r.63-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutz</artifactId>
<version>1.r.63-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,16 @@
package org.nutz.boot.starter.quartz;
import org.nutz.boot.ioc.IocLoaderProvider;
import org.nutz.integration.quartz.QuartzIocLoader;
import org.nutz.ioc.IocLoader;
import org.nutz.ioc.loader.annotation.IocBean;
@IocBean
public class QuartzStarter implements IocLoaderProvider {
public IocLoader getIocLoader() {
return new QuartzIocLoader();
}
}

View File

@ -0,0 +1 @@
org.nutz.boot.starter.quartz.QuartzStarter

View File

@ -1,10 +0,0 @@
package org.nutz.boot.starter;
import javax.servlet.ServletContextListener;
public class ShiroEnv implements WebContextListenerFace {
public ServletContextListener getServletContextListener() {
return new org.apache.shiro.web.env.EnvironmentLoaderListener();
}
}

View File

@ -0,0 +1,12 @@
package org.nutz.boot.starter.shiro;
import java.util.EventListener;
import org.nutz.boot.starter.WebEventListenerFace;
public class ShiroEnv implements WebEventListenerFace {
public EventListener getEventListener() {
return new org.apache.shiro.web.env.EnvironmentLoaderListener();
}
}

View File

@ -1,4 +1,4 @@
package org.nutz.boot.starter;
package org.nutz.boot.starter.shiro;
import java.util.EnumSet;
import java.util.HashMap;
@ -7,6 +7,7 @@ import java.util.Map;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import org.nutz.boot.starter.WebFilterFace;
import org.nutz.integration.shiro.ShiroFilter2;
public class ShiroFilterStarter implements WebFilterFace {

View File

@ -1 +1 @@
org.nutz.boot.starter.jetty.JettyStarter
org.nutz.boot.starter.shiro.ShiroFilterStarter

View File

@ -1,4 +1,4 @@
package org.nutz.boot.starter.weixin;
package org.nutz.boot.starter.nutz.weixin;
import org.nutz.boot.ioc.IocLoaderProvider;
import org.nutz.ioc.IocLoader;

View File

@ -1 +1 @@
org.nutz.boot.starter.weixin.WeixinStarter
org.nutz.boot.starter.nutz.weixin.WeixinStarter

View File

@ -1,5 +0,0 @@
package org.nutz.boot.starter;
public interface WebContextListenerFace {
}

View File

@ -0,0 +1,8 @@
package org.nutz.boot.starter;
import java.util.EventListener;
public interface WebEventListenerFace {
EventListener getEventListener();
}

View File

@ -7,6 +7,7 @@
<packaging>pom</packaging>
<modules>
<module>nutzboot-starter</module>
<module>nutzboot-demo</module>
<module>nutzboot-starter-jetty</module>
<module>nutzboot-starter-undertow</module>
<module>nutzboot-starter-tomcat</module>
@ -26,8 +27,8 @@
<module>nutzboot-starter-rabbitmq</module>
<module>nutzboot-starter-jdbc</module>
<module>nutzboot-starter-nutz</module>
<module>nutzboot-demo</module>
<module>nutzboot-starter-weixin</module>
<module>nutzboot-starter-quartz</module>
</modules>
<repositories>
<repository>