Skip to content

Commit 99781e1

Browse files
author
孙健
committed
fix some bug
1 parent 8103f4f commit 99781e1

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'nlpcn.org'
2-
version '3.0.0'
2+
version '3.1.0'
33

44
apply plugin: 'java'
55
apply plugin: 'war'

src/main/java/org/nlpcn/jcoder/util/Testing.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,9 @@ public static void startServer(String iocPath, String[] packages) throws Excepti
194194
startServer(8080, iocPath, null, packages);
195195
}
196196

197+
198+
public static void main(String[] args) throws Exception {
199+
startServer("D:\\git\\mss-api\\src\\test\\resources\\ioc.js", new String[]{"cn"});
200+
}
197201

198202
}

src/main/java/org/nlpcn/jcoder/util/TestingFilter.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,27 @@ public static void init(String... packages) throws IOException {
4747
list.forEach(cla -> {
4848
Object obj = null;
4949
Single single = Mirror.getAnnotationDeep(cla, Single.class);
50-
if (single == null || !single.value()) {
51-
try {
52-
obj = cla.newInstance();
53-
} catch (Exception e) {
54-
e.printStackTrace();
55-
}
56-
}
5750

5851
for (Method method : cla.getMethods()) {
5952
if (!Modifier.isPublic(method.getModifiers()) || method.isBridge() || method.getDeclaringClass() != cla) {
6053
continue;
6154
}
55+
6256
if (Mirror.getAnnotationDeep(method, Execute.class) != null || Mirror.getAnnotationDeep(method, DefaultExecute.class) != null) {
63-
tempMethods.put(cla.getSimpleName() + "/" + method.getName(), KeyValue.with(method, obj));
57+
if (obj == null && (single == null || single.value())) { //用懒加载方式
58+
try {
59+
obj = cla.newInstance();
60+
} catch (Exception e) {
61+
e.printStackTrace();
62+
}
63+
}
64+
String path = cla.getSimpleName() + "/" + method.getName();
65+
LOG.info("find api : " + path);
66+
tempMethods.put(path, KeyValue.with(method, obj));
6467
}
6568
}
69+
70+
obj = null;
6671
});
6772
}
6873

@@ -161,5 +166,5 @@ public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain
161166
public void destroy() {
162167
System.out.println("destroy");
163168
}
164-
169+
165170
}

src/main/webapp/apidoc/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ <h2 ng-show="y.attr">Attribute</h2>
106106
</table>
107107

108108
<h2 ng-show="y.retrunContent">Return</h2>
109-
<pre class="prettyprint prettyprinted" ng-show="y.retrunContent"><code>{{y.retrunContent}}</code></pre>
109+
<pre class="prettyprint language-json" data-type="json" ng-show="y.retrunContent"><code>{{y.retrunContent}}</code></pre>
110110

111111
</article>
112112
</div>

src/test/java/cn/com/infcn/api/test/TaskDemo.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22

33
import org.apache.log4j.Logger;
44
import org.nlpcn.jcoder.run.annotation.DefaultExecute;
5-
import org.nlpcn.jcoder.util.StaticValue;
5+
import org.nlpcn.jcoder.run.annotation.Single;
66
import org.nutz.ioc.loader.annotation.Inject;
77

8+
@Single(true)
89
public class TaskDemo {
910

1011
@Inject
1112
private Logger log;
13+
14+
int i = 0 ;
1215

16+
/**
17+
* 测试
18+
*
19+
* @return {"FBI":[{"name":"rose","age":"25"},{"name":"jack","age":"23"}],"NBA":[{"name":"tom","sex":"man"},{"name":"jack","sex":"women"}],"NBA":[{"name":"tom","sex":"man"},{"name":"jack","sex":"women"}],"NBA":[{"name":"tom","sex":"man"},{"name":"jack","sex":"women"}],"NBA":[{"name":"tom","sex":"man"},{"name":"jack","sex":"women"}],"NBA":[{"name":"tom","sex":"man"},{"name":"jack","sex":"women"}],"NBA":[{"name":"tom","sex":"man"},{"name":"jack","sex":"women"}]}
20+
*/
1321
@DefaultExecute
1422
public Object execute() {
15-
return StaticValue.getUserIoc().getNames();
23+
return i++;
1624
}
1725
}

0 commit comments

Comments
 (0)