小编Dav*_*ler的帖子

Vertx-web:我在哪里放置webroot文件夹?

这应该是一个简单的,但它还没有到目前为止.我一直在努力工作vert.x 2vert.x 3最近改用.我以为我会尝试一个简单的vertx-web示例,但无法通过简单的静态文件提供.

我的服务器类包含以下代码段:

    HttpServer server = vertx.createHttpServer();
    Router router = ...;
    router.route("/static/*").handler(StaticHandler.create().setCachingEnabled(false));
    server.requestHandler(router::accept).listen(ctx.port);
Run Code Online (Sandbox Code Playgroud)

我正在使用Eclipse,但也尝试vertx从命令行运行.我也在使用Maven.我有三个webroot文件夹,并且vert.x找不到它们:

myproject/webroot
myproject/src/main/resources/webroot
myproject/src/main/java/webroot
Run Code Online (Sandbox Code Playgroud)

每个'webroot'都包含一个index.html和一个css/base.css文件.

第一个是在我项目的根文件夹中.第二个是在Maven资源文件夹中,第三个应该是我的classpath.在我的Eclipse运行配置中,我将myproject/src/main/resources/webroot添加到类路径中,并确保我的工作目录设置为'myproject'.从命令行运行时,我在myproject目录中,我的脚本如下所示:

JAVA_OPTS="-Dmyproject.port=8099" CLASSPATH="src/main/java:src/main/resources:target/dependencies/*:target/classes" vertx run com.my.MyProject
Run Code Online (Sandbox Code Playgroud)

无论如何,当我尝试这些URL时,我总是得到404:

http://localhost:8099
http://localhost:8099/
http://localhost:8099/index.html
http://localhost:8099/static/css/base.css
Run Code Online (Sandbox Code Playgroud)

还有什么我需要做的吗?

java vert.x

14
推荐指数
4
解决办法
1万
查看次数

Scala调度示例

我是一名Java工程师,他最近一直在慢慢学习Scala.我发现了一些使用Dispatch的示例代码来制作一个简单的GET请求:

val request = url("http://somesite.com")
val result = Http( request OK as.String)
Run Code Online (Sandbox Code Playgroud)

问题是......我不太明白这里发生了什么.首先,是Http一类?还是一种方法?第二,传递给它的参数是什么?我想也许我们传递了三个参数,Scala允许我们省略逗号.但是当我尝试添加逗号时,我遇到了编译错误,所以这不可能是正确的.

我确信这对于精通Scala的人来说是有道理的,但我还没有,而且它阻止了我.我曾尝试在线查找文档,但没有发现任何有用的信息.

scala

12
推荐指数
2
解决办法
3427
查看次数

Hibernate saveOrUpdate()尝试在应该更新时保存

我有一个名为IssueParticipant的Hibernate实体.它基本上描述了用户和问题之间的关系(类似于JIRA或Bugzilla问题).它表示数据库中的一种多对多链接表,将用户ID链接到问题ID,但还包括与通知设置相关的其他信息,因此将其视为自己的实体.

我使用userId和issueId作为复合键时遇到了很大的问题,因此我创建了一个合成键,它是一个String(和postgres数据库中的varchar),形成如下:_.

现在,我有一个屏幕,用户可以编辑与问题相关的所有用户,同时还可以编辑通知设置.在控制器类中,我创建一个IssueParticipants列表,如下所示:

IssueParticipant participant = new IssueParticipant();
participant.setUser(accountUser);
participant.setIssue(issue);
Run Code Online (Sandbox Code Playgroud)

所以这些当然不是由Hibernate管理的.

然后在我的DAO中,我遍历它们并调用saveOrUpdate(),期望如果数据库中存在具有相同合成密钥的IssueParticipant,它将更新; 否则将被插入:

    for (IssueParticipant participant : participants) {
        getCurrentSession().saveOrUpdate(participant);
        savedIds.add(participant.getIssueUserKey());
    }
Run Code Online (Sandbox Code Playgroud)

(savedIds是我正在维护的列表,以便稍后我将知道我应该从数据库中删除哪些IssueParticipants).

而不是我期望的,我得到一个例外:

org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "issue_participant_pkey"
Run Code Online (Sandbox Code Playgroud)

这是我的实体类,缩写为:

public class IssueParticipant extends Entity {

    private String issueUserKey;
    private Long issueId;
    private Long userId;

     // Edit: adding 'dateAdded' definition
    private Date dateAdded;
// ...

    // below may be null
    private SPUser user;
    private Issue issue;

    public static IssueParticipant nulledIssueParticipant() {
        IssueParticipant ip = new IssueParticipant(); …
Run Code Online (Sandbox Code Playgroud)

java hibernate

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

SpringMVC app ...为什么app上下文被初始化两次?

我之前在这些论坛上看过这个基本问题,但没有一个答案似乎解决了我的特定问题.无论如何,我有一个小的Spring webapp,包括一个核心Spring业务层,SpringMVC和Spring-Quartz(我也使用MyBatis,虽然我不相信这是相关的).我的所有Spring库都是3.1.3

问题是,当我将我的应用程序部署到Tomcat 6时,通常会将根应用程序上下文和Web应用程序上下文分别初始化两次.通过查看日志可以看出这一点,而且当我的Quartz作业应该触发一次时触发两次这一事实也很明显(后一点是为什么这不仅仅是一个理论问题).

我以为我的应用程序上下文都已整理好了,但显然必定会有一些我不知道的东西.我的一般方法是:

  1. 将基本的Spring配置放在类路径的spring-biz-context.xml中(即它在WEB-INF/classes/com/me/config中结束)
  2. 将Spring Quartz配置放在spring-quartz-context.xml中,在类路径中(即它也在WEB-INF/classes/com/me/config中结束)
  3. applicationContext.xml文件放在WEB-INF中; 让它简单地导入上面两个XML文件
  4. web.xml中声明ContextLoaderListener ,以便webapp将查找上述applicationContext.xml文件,从而初始化根上下文.
  5. web.xml中声明一个名为UsMain的servlet(类型为DispatcherServlet)
  6. 在WEB-INF中创建一个UsMain-servlet.xml文件,其中包含一些仅用于Web应用程序上下文的最小内容.

下面是我的配置文件,减去所有的XML文件:

UsMain-servlet.xml中

    <bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

<mvc:resources mapping="/rsc/**" location="/rsc/" cache-period="31556926"/>

<mvc:annotation-driven />

<context:component-scan base-package="com.me.controllers" />
Run Code Online (Sandbox Code Playgroud)

web.xml中

<web-app ... version="2.5">
...

  <servlet>
<servlet-name>UsMain</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
<servlet-name>UsMain</servlet-name>
<url-pattern>/</url-pattern>
  </servlet-mapping>

<listener>  
    <listener-class>  
        org.springframework.web.context.ContextLoaderListener  
    </listener-class>  
</listener>

</web-app>
Run Code Online (Sandbox Code Playgroud)

applicationContext.xml中

    <import resource="classes/com/me/config/spring-biz-context.xml" />
<import resource="classes/com/me/config/spring-quartz-context.xml" /> …
Run Code Online (Sandbox Code Playgroud)

spring tomcat spring-mvc applicationcontext

5
推荐指数
2
解决办法
1969
查看次数

厨师和postgres; 我该如何指定密码?

我是厨师的新手,我正在尝试解释文档.我已将opscode postgresql配方添加到我的chef-solo环境中.postgresql似乎安装和启动就好了,但不幸的是我无法登录到服务器,使其几乎无法使用.

文档提到了这一点:

使用chef-client时,以下节点属性存储在Chef服务器上.因为chef-solo根本没有连接到服务器或保存节点对象,所以要在chef-solo运行中保持密码,必须在使用的json_attribs文件中指定它们.例如:

{
  "postgresql": {
    "password": {
      "postgres": "iloverandompasswordsbutthiswilldo"
    }
  },
  "run_list": ["recipe[postgresql::server]"]
}
Run Code Online (Sandbox Code Playgroud)

但是,我不知道"json_attribs"文件是什么.配方本身不包含这样的文件,我尝试使用谷歌搜索,没有结果.我也尝试创建这样一个文件并将其粘贴在我的目录结构中的随机位置,但当然这不起作用.

并且通过"没有工作",我的意思是我带来了流浪汉,ssh'ed,并尝试"psql -U postgres -W",然后输入我创建的密码...但总是得到一个身份验证错误.另请注意,我理解我为密码提供的值(例如,代替上面示例中的"iloverandompasswordsbutthiswilldo")应该是密码的MD5哈希值,而不是明文,这就是我提供的内容.

postgresql chef-infra vagrant

4
推荐指数
1
解决办法
4627
查看次数

乐器和僵尸; 保留计数是1,2,然后突然-1!

我有Cocoa桌面应用程序,就像许多人使用NSDates一样.现在,其中一个NSDates正在变成一个僵尸.它被用在NSUndoManager的堆栈中,所以我认为有些东西我不太了解.但这没关系,因为我打算使用Instruments来找出它被保留和释放的位置.除此之外,仪器显示出非常奇怪的行为(但我之前看过一次或两次的行为).我在http://taubler.com/zombie.png上发布了一个屏幕截图,并试图重现仪器的跟踪:

0   __NSCFDate  Malloc  1   00:08.416.441   0x114a92150 16  Foundation  getObjectValue
1   __NSCFDate  Autorelease     00:08.416.462   0x114a92150 0   Foundation  getObjectValue
2   __NSCFDate  Retain  2   00:08.416.576   0x114a92150 0   Proxy   -[SPTask setStart:]
3   __NSCFDate  Release 1   00:09.815.661   0x114a92150 0   Foundation  -[NSAutoreleasePool drain]
4   __NSCFDate  Retain  2   00:10.703.345   0x114a92150 0   Proxy   -[DraggingTask setOrigStart:]
5   __NSCFDate  Release 1   00:10.871.257   0x114a92150 0   Proxy   -[SPTask setStart:]
6   __NSCFDate  Retain  2   00:11.482.473   0x114a92150 0   Foundation  -[NSCFArray insertObject:atIndex:]
7   __NSCFDate  Zombie  -1  00:18.639.856   0x114a92150 0   Proxy   -[SPTask setStart:] …
Run Code Online (Sandbox Code Playgroud)

cocoa cocoa-touch objective-c instruments

3
推荐指数
1
解决办法
405
查看次数

Spring Aspects没有执行

我一直在努力为Spring MVC webapp添加方面,并且方面没有执行.我试图把它煮成一些简单的东西,显然应该可以工作,但仍然没有去.这就是我现在所处的位置:

// imports...
@Aspect
public class AuthCheckerAspect {
    {
        System.out.println("initting");
    }

    @Pointcut("execution(* * *(..))")
    public void c() {}

    @Before("c")
    public void cc(JoinPoint pjp) throws Throwable {
        System.out.println("test...");
    }
 }
Run Code Online (Sandbox Code Playgroud)

据我所知,切入点应该适用于任何Spring托管类中的任何方法(我的应用程序中有很多).我还在Spring配置中添加了以下内容:

<aop:aspectj-autoproxy/>
Run Code Online (Sandbox Code Playgroud)

我在cc()方法的System.out.println()语句中设置了一个断点,但它从未被捕获(是的,我肯定是附加了调试器;其他断点正确捕获).我怀疑AuthCheckerAspect类永远不会被加载到Spring上下文中,因为我还在初始化器子句中设置了一个断点,并且从不捕获; 当我对其他Spring管理的类做同样的事情时,他们的断点总是在app启动时捕获.

我还需要做些什么吗?

提前致谢.

aop spring aspectj

3
推荐指数
1
解决办法
4965
查看次数

Spring Data,Mongo和@TypeAlias:阅读不起作用

问题

一段时间后,我开始使用MongoDB和Spring Data.我保留了大部分默认功能,因此我的所有文档都存储在MongoDB中,并带有_class指向实体的完全限定类名的字段.

马上就没有"闻到"我的权利,但我一个人离开了.直到最近,当我重构了一堆代码时,突然间我的所有文档都无法从MongoDB中读回并转换为它们的(重构/重命名)Java实体.我很快意识到这是因为现在有一个完全合格的类名不匹配.我也很快意识到 - 鉴于我将来可能会再次重构 - 如果我不希望我的所有数据都变得无法使用,我需要找出其他的东西.

我试过的

这就是我正在做的事情,但我已经碰壁了.我我需要做以下事情:

  • 使用@TypeAlias("ta")"ta"是唯一的稳定字符串来标注每个实体.
  • 配置和使用不同TypeInformationMapper的Spring Data,以便在将文档转换回Java实体时使用; 例如,它需要知道"widget.foo"的类型别名是指com.myapp.document.FooWidget.

我确定我应该使用一种TypeInformationMapper类型org.springframework.data.convert.MappingContextTypeInformationMapper.据推测,MappingContextTypeInformationMapper将扫描我的实体/文档以查找@ TypeAlias的文档并存储别名 - > to->类映射.但我无法将其传递给我的MappingMongoConverter; 我必须传递MongoTypeMapper的子类型.所以我正在配置一个DefaultMongoTypeMapper,并将一个List MappingContextTypeInformationMapper作为其"mappers"构造函数arg 传递.

这是我的spring XML配置的相关部分:

<bean id="mongoTypeMapper" class="org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper">
    <constructor-arg name="typeKey" value="_class"></constructor-arg>
    <constructor-arg name="mappers">
        <list>
            <ref bean="mappingContextTypeMapper" />
        </list>
    </constructor-arg> 
</bean>

<bean id="mappingContextTypeMapper" class="org.springframework.data.convert.MappingContextTypeInformationMapper">
    <constructor-arg ref="mappingContext" />
</bean>

<bean id="mappingMongoConverter"
    class="org.springframework.data.mongodb.core.convert.MappingMongoConverter">
    <constructor-arg ref="mongoDbFactory" />
    <constructor-arg ref="mappingContext" />
    <property name="mapKeyDotReplacement" value="__dot__" />
    <property name="typeMapper" ref="mongoTypeMapper"/> …
Run Code Online (Sandbox Code Playgroud)

java mongodb spring-data

3
推荐指数
2
解决办法
5673
查看次数