小编Joh*_*ube的帖子

Guice + Jersey:添加所有资源和提供程序而不绑定到Jersey Servlet

我目前正在使用Jersey 1.8和Guice 3.0为我的JPA进行DI的泽西应用.这很好地解决了一个我无法克服的主要问题:

我必须使用bind手动将所有Jersey资源类添加到JerseyServletModule:

@Override
protected Injector getInjector() {
    return Guice.createInjector(new JerseyServletModule() {

        @Override
        protected void configureServlets() {

            install(new JpaPersistModule("DBName"));
            filter("/*").through(PersistFilter.class);

            /* bind the REST resources and serve*/
            bind(Hello.class);
            serve("/*").with(GuiceContainer.class);

        }
    });
}
Run Code Online (Sandbox Code Playgroud)

我希望能够省略对每个资源和提供者使用bind,并在jersey-guice doc中找到一条评论:http://jersey.java.net/nonav/apidocs/1.8/contribs/jersey-guice /com/sun/jersey/guice/spi/container/servlet/package-summary.html

它基本上表明可以将球衣资源的注册传递给球衣servlet.但是我无法使用所述方法来管理它:

@Override
     protected Injector getInjector() {
         return Guice.createInjector(new JerseyServletModule() {

             @Override
             protected void configureServlets() {
                 bind(GuiceResource.class);

                 Map<String, String> params = new HashMap<String, String>();
                 params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "unbound");
                 serve("/*").with(GuiceContainer.class, params);
             }
         }
     });
Run Code Online (Sandbox Code Playgroud)

可悲的是,我无法获得有关球衣资源注册过程的更多信息.

任何帮助,将不胜感激.当然,如果需要,我可以提供额外的信息!谢谢.

java jersey guice

10
推荐指数
1
解决办法
5315
查看次数

使用fs.readFileSync和eval内容读取文件...哪个范围具有这些功能?怎么访问?

我最近尝试将文件导入到现有的node.js项目中.我知道这应该用模块编写,但我包括我的外部javascript文件,如下所示:

 eval(fs.readFileSync('public/templates/simple.js')+'')
Run Code Online (Sandbox Code Playgroud)

simple.js的内容如下所示:

if (typeof examples == 'undefined') { var examples = {}; }
if (typeof examples.simple == 'undefined') { examples.simple = {}; }


examples.simple.helloWorld = function(opt_data, opt_sb) {
 var output = opt_sb || new soy.StringBuilder();
 output.append('Hello world!');
 return opt_sb ? '' : output.toString();
};
Run Code Online (Sandbox Code Playgroud)

(是的,谷歌关闭模板).

我现在可以使用以下方法调用模板文件:

examples.simple.helloWorld();
Run Code Online (Sandbox Code Playgroud)

一切都像预期的那样工作.但是,我无法弄清楚这些函数的范围是什么以及我可以访问示例对象的位置.

一切都在node.js 0.8服务器上运行,就像我说它的工作......我只是不知道为什么?

谢谢你的澄清.

javascript eval fs node.js google-closure-templates

8
推荐指数
1
解决办法
9367
查看次数

为Google Charts Api编写自定义格式化程序

我想创建一个图表来显示我在10k跑步的时间.一切都正常,我唯一的问题是,我想格式化时间的显示方式.

目前,时间显示为表示秒数的数字.例如,30分钟的运行时间降至10800秒.谷歌提供的格式化程序确实涵盖了很多东西,但我对它们提供的内容并不满意.

http://code.google.com/apis/chart/interactive/docs/reference.html#formatters

遗憾的是,没有关于如何实现自己的格式化程序的信息.我有可能扩展格式化程序,还是有需要实现的接口?

我要做的第一件事就是将数字10800解析为30:00.00(30分钟,0秒,0毫秒)的美好时光.也许这已经可以使用patternformatter,但我不知道如何,因为涉及计算并且不知道如何在patternformatter中实现它.

谢谢您的帮助.约翰尼

javascript api charts google-visualization

6
推荐指数
1
解决办法
2362
查看次数

寻找可以在Java和JavaScript中使用的模板引擎

正如标题所说,我目前正在寻找一个适用于Java和Javascript的模板引擎.我的想法是,我的ajax json对象可以使用相同的模板文件来呈现客户端,就像Java在服务器端一样.

我知道有google-closure-template但它正在使用guice 2.0并且我当前的项目在guice 3.0下运行并且两者一起创建了奇怪的错误并且我尝试使用它们但是失败了大约2周了...

除谷歌关闭之外还有什么吗?

javascript java template-engine google-closure

5
推荐指数
1
解决办法
1169
查看次数

当我使用子路径时,Express加载控制器无限时间和浏览器窗口崩溃

我目前正在使用angularJS,我尝试建立一个主页.我的routeconfig看起来像这样:

var app = angular.module('mml-annie', ['mmlServices']);

app.config(['$locationProvider', function($location) {
  $location.html5Mode(true); //now there won't be a hashbang within URLs for browers that     support HTML5 history
}]);

app.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/team', {
    templateUrl: 'partials/team', 
    controller: TeamCtrl
}).

otherwise({
        redirectTo: '/home'
    });
}]);
Run Code Online (Sandbox Code Playgroud)

出于测试目的,我的控制器看起来像这样:

function TeamCtrl($scope, Team) {

console.log("TEST");
}
Run Code Online (Sandbox Code Playgroud)

除了我的路径获得添加/字段之外,我工作得很好.当我更改"/team""/team/team/test"我的应用程序调用控制器,直到应用程序崩溃.不使用html5模式修复了这个问题.但我宁愿使用漂亮的HTML5模式而不使用hashbang.

该应用程序node.js使用express 运行,为除API调用之外的所有请求提供角度应用程序.

你知道发生了什么吗?我不知道......
当然,如果需要,我可以提供更多信息.

javascript node.js express angularjs

0
推荐指数
1
解决办法
535
查看次数