我们刚刚在Amazon Linux上升级到Java 8.我们正在使用Spring 4.3.8.RELEASE.过去我们可以通过在应用程序上下文文件中设置bean来获取我们的机器主机名,就像这样...
<bean id="localhostInetAddress" class="java.net.InetAddress" factory-method="getLocalHost" />
<bean id="hostname" factory-bean="localhostInetAddress" factory-method="getHostName" />
Run Code Online (Sandbox Code Playgroud)
但是对于Java 8,bean"hostname"现在包含字符串
localhost
Run Code Online (Sandbox Code Playgroud)
在Java 8之前,它曾用于包含在命令行上运行的"hostname"值,即
[myuser@machine1 ~]$ hostname
machine1.mydomain.org
Run Code Online (Sandbox Code Playgroud)
如何重新配置我们的bean,以便它获取命令行列出的主机名?我不想在任何地方硬编码.
我正在使用Mockito 1.9.5.如何模拟受保护方法返回的内容?我有这种受保护的方法......
protected JSONObject myMethod(final String param1, final String param2)
{
…
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在JUnit中执行此操作时:
    final MyService mymock = Mockito.mock(MyService.class, Mockito.CALLS_REAL_METHODS);        
    final String pararm1 = “param1”;
    Mockito.doReturn(myData).when(mymock).myMethod(param1, param2);
Run Code Online (Sandbox Code Playgroud)
在最后一行,我得到一个编译错误"方法'myMethod'不可见."我如何使用Mockito来模拟受保护的方法?如果这是答案,我愿意升级我的版本.
我正在使用Java 6.
我无法让我的内部类使用与其封闭类相同的泛型类.目前我有
public class TernarySearchTree < T > {
    ...
    protected class TSTNode < T > {
        // index values for accessing relatives array
        protected static final int PARENT = 0, LOKID = 1, EQKID = 2, HIKID = 3; 
        protected char splitchar;
        protected TSTNode < T > [] relatives;
        private T data;
        protected TSTNode(char splitchar, TSTNode < T > parent) {
            this.splitchar = splitchar;
            relatives = new TSTNode[4];
            relatives[PARENT] = parent;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)
现在我收到了警告
类型参数T隐藏类型T.
如果我从内部类中删除类型参数(即<T> …
我正在使用MySql 5.5.37.作为root,我正试图杀死一个锁定某些表的事务.我跑
SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX\G   
Run Code Online (Sandbox Code Playgroud)
并获得输出
…
*************************** 6. row ***************************
                    trx_id: 143E6CDE
                 trx_state: RUNNING
               trx_started: 2014-10-20 06:03:56
     trx_requested_lock_id: NULL
          trx_wait_started: NULL
                trx_weight: 2305887
       trx_mysql_thread_id: 158360
                 trx_query: delete from event where id not in (select q.* from (select e.id FROM event e, (select object_id, max(date_processed) d from event group by object_id) o where e.object_id = o.object_id and e.date_processed = o.d) q)
       trx_operation_state: NULL
         trx_tables_in_use: 3
         trx_tables_locked: 3
          trx_lock_structs: 210634
     trx_lock_memory_bytes: 19790264
           trx_rows_locked: 10668793
         trx_rows_modified: 2095253
   trx_concurrency_tickets: 0
       trx_isolation_level: REPEATABLE …Run Code Online (Sandbox Code Playgroud) 我正在使用MySql 5.5.37.我有一个包含以下列的表
+------------------+------------------+------+-----+---------+-------+
| Field            | Type             | Null | Key | Default | Extra |
+------------------+------------------+------+-----+---------+-------+
| ID               | varchar(32)      | NO   | PRI | NULL    |       |
| CODE             | varchar(6)       | NO   | UNI | NULL    |       |
Run Code Online (Sandbox Code Playgroud)
代码列是唯一的,我的ID列是GUID.根据上表中的某些条件(例如WHERE COLUMN1 = 0),我想要更新多行.如何为我的CODE列生成随机的,唯一的6个字符的代码(理想情况是字母和数字),以便它们不违反我表中的唯一约束?请注意,表中不符合条件的列(例如,其中COLUMN1 <> 0)已经具有CODE列的唯一值.
编辑:这与这个问题不同 - 使用MySQL生成随机和唯一的8个字符串,因为该链接处理ID taht是数字.我的ID是32个字符的字符串.此外,他们的解决方案没有考虑在运行我想要运行的语句之前表中可能有值的事实,这将为相关列生成唯一值.
我正在使用Maven 3.0.3.对于我们的项目集成测试,我们需要使用Unix命令创建虚拟帧缓冲区.但是,当我们在Windows机器上运行我们的项目时,我们不需要这个.我们用
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <id>start-xvfb</id>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <echo message="Starting xvfb ..." />
                            <exec executable="Xvfb" spawn="true">
                                <arg value=":0.0" />
                            </exec>
                        </tasks>
                    </configuration>
                </execution>
                <execution>
                    <id>shutdown-xvfb</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <echo message="Ending xvfb ..." />
                            <exec executable="killall">
                                <arg value="Xvfb" />
                            </exec>
                        </tasks>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)
当平台不是windows时,如何进行上述运行并禁止运行插件?谢谢, - 戴夫
我在这个版本的Linux上使用节点5.10.0
[davea@mydevbox mydir]$ uname -a
Linux mydevbox.mydomain.com 7.3.8-25.26.amzn1.x86_64 #1 SMP Wed Mar 16 17:15:34 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
运行我的脚本时出现以下错误("服务器提前终止,状态为127").我已经确认我可以使用"wget"来访问相关网址,所以我不知道还有什么我需要让这件事工作......
[davea@mydevbox mydir]$ node myscript.js 
Validation Complete
/home/davea/node_modules/selenium-webdriver/lib/promise.js:654
    throw error;
    ^
Error: Server terminated early with status 127
    at Error (native)
    at /home/davea/node_modules/selenium-webdriver/remote/index.js:242:20
    at ManagedPromise.invokeCallback_ (/home/davea/node_modules/selenium-webdriver/lib/promise.js:1343:14)
    at TaskQueue.execute_ (/home/davea/node_modules/selenium-webdriver/lib/promise.js:2868:14)
    at TaskQueue.executeNext_ (/home/davea/node_modules/selenium-webdriver/lib/promise.js:2851:21)
    at /home/davea/node_modules/selenium-webdriver/lib/promise.js:2730:27
    at /home/davea/node_modules/selenium-webdriver/lib/promise.js:639:7
    at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: WebDriver.createSession()
    at acquireSession (/home/davea/node_modules/selenium-webdriver/lib/webdriver.js:107:22)
    at Function.createSession (/home/davea/node_modules/selenium-webdriver/lib/webdriver.js:337:12)
    at Driver (/home/davea/node_modules/selenium-webdriver/chrome.js:778:38)
    at Builder.build (/home/davea/node_modules/selenium-webdriver/builder.js:464:16)
    at Object.<anonymous> (/home/davea/mydir/js/Optimus.js:14:4)
    at Module._compile (module.js:413:34) …Run Code Online (Sandbox Code Playgroud) 我正在使用 Jest 和 Typescript。我有一个不返回任何内容的异步函数(void)。我如何模拟返回 void?我尝试了下面的
const myMockFn = jest.fn().mockImplementationOnce(() => Promise.resolve(void));
jest.mock('../config', () => ({
  setup: async () =>
  myMockFn(),
}));
Run Code Online (Sandbox Code Playgroud)
但我收到编译错误
Expression expected.
Run Code Online (Sandbox Code Playgroud)
与“Promise.resolve(void)”相关。
我正在使用JPA 2.0.Hibernate 4.1.0.Final和Java 6.如何从以下psuedo-SQL编写JPA查询?
select max(e.dateProcessed) from Event e where e.org = myOrg
Run Code Online (Sandbox Code Playgroud)
我的域对象如下所示:
@GenericGenerator(name = "uuid-strategy", strategy = "org.mainco.subco.core.util.subcoUUIDGenerator")
@Entity
@Table(name = "sb__event",
    uniqueConstraints = { @UniqueConstraint(columnNames={"EVENT_ID"}) }
)
public class Event
{
    @Id
    @Column(name = "ID")
    @GeneratedValue(generator = "uuid-strategy")
    private String id;
    @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.REMOVE})
    @JoinColumn(name = "ORGANIZATION_ID", nullable = false, updatable = true)
    private Organization org;
    @Column(name = "DATE_PROCESSED")
    @NotNull
    private java.util.Date dateProcessed;
Run Code Online (Sandbox Code Playgroud)
我知道CriteriaBuilder.greatest参与其中,但我无法弄清楚如何编写查询.这将返回与组织匹配的所有事件对象,但这就是我所获得的.
final CriteriaBuilder builder = m_entityManager.getCriteriaBuilder();
final CriteriaQuery<Event> criteria = builder.createQuery(Event.class); …Run Code Online (Sandbox Code Playgroud) 我正在使用Rails 5.我想使用下面的代码解析.xls(不要与.xlsx doc混淆)
  book = Roo::Spreadsheet.open(file_location)
  sheet = book.sheet(0)
  text = sheet.to_csv
  csv = CSV.parse(text)
  arr_of_arrs = csv
  text_content = ""
  arr_of_arrs.each do |arr|
    arr.map!{|v| v && v.to_f < 1 && v.to_f > 0 ? TimeFormattingHelper.time_as_str(v.to_f * 24 * 3600 * 1000) : v}
    text_content = "#{text_content}\n#{arr.join("\t")}"
  end
Run Code Online (Sandbox Code Playgroud)
这是我在上面引用的方法
  def time_as_str(time_in_ms)
    regex = /^(0*:?)*0*/
    Time.at(time_in_ms.to_f/1000).utc.strftime("%H:%M:%S.%1N").sub!(regex, '')
  end
Run Code Online (Sandbox Code Playgroud)
我遇到麻烦的一个方面是我的.xls doc中出现的单元格
24:08:00
Run Code Online (Sandbox Code Playgroud)
被处理为
1904-01-02T00:08:00+00:00
Run Code Online (Sandbox Code Playgroud)
使用上面的代码.如何解析我在屏幕上看到的值?也就是说,如何将日期值转换为时间值?
作为另一个Excel文档的示例,显示为的单元格
24:02:00
Run Code Online (Sandbox Code Playgroud)
正在被上面的代码解析为
1899-12-31T00:02:00+00:00
Run Code Online (Sandbox Code Playgroud) java ×2
linux ×2
mocking ×2
mysql ×2
constraints ×1
criteria ×1
deadlock ×1
generics ×1
hibernate ×1
hostname ×1
java-6 ×1
java-8 ×1
jpa ×1
jpa-2.0 ×1
junit ×1
kill ×1
maven ×1
max ×1
mockito ×1
node.js ×1
promise ×1
protected ×1
random ×1
roo-gem ×1
root ×1
spring ×1
sql-update ×1
transactions ×1
ts-jest ×1
typescript ×1
unique ×1
void ×1
xls ×1