我想了解动态规划的概念,通过对MIT OCW课程在这里.关于OCW视频的解释很棒,但我觉得在我将解释实现到代码之前我并不理解它.在实施时,我会参考这里的讲义中的一些注释,特别是注释的第3页.
问题是,我不知道如何将一些数学符号转换为代码.这是我实施的解决方案的一部分(并认为它是正确实现的):
import math
paragraph = "Some long lorem ipsum text."
words = paragraph.split(" ")
# Count total length for all strings in a list of strings.
# This function will be used by the badness function below.
def total_length(str_arr):
total = 0
for string in str_arr:
total = total + len(string)
total = total + len(str_arr) # spaces
return total
# Calculate the badness score for a word.
# str_arr is assumed be send …Run Code Online (Sandbox Code Playgroud) 我正在按照本指南学习如何使用spring-rabbitRabbitMQ.但是在本指南中,RabbitMQ配置是默认配置(localhost服务器,凭证为guest/guest).如果我想用ip地址和凭证连接到远程RabbitMQ,我该怎么办?我不知道在我的应用程序中将这些信息设置在何处.
rabbitmq spring-rabbit spring-amqp spring-boot spring-rabbitmq
@Test(expectedExceptions=DataAccessException.class)
public void testUpdateSubModuleOrderDateExceptionCheck() {
//some code to initialize//
UserSubModuleDao userSubModuleDao = mock(UserSubModuleDao.class);
userModuleServiceImpl.setUserSubModuleDao(userSubModuleDao);
UserSubModule userSubModule=new UserSubModule();
UserSubModuleId userSubModuleId=new UserSubModuleId();
when(userSubModuleDao.findById(any(UserSubModuleId.class),eq(false))).thenThrow(DataAccessException.class);
userModuleServiceImpl.updateSubModuleOrder(data, moduleSysId, userId);
Run Code Online (Sandbox Code Playgroud)
我想为代码覆盖抛出Db异常.它的工作如果我给出预期的例外:Exception.class但不是DataAccessException.class
原始类中的方法如下:
public void updateSubModuleOrder(Long[] data, Long moduleSysId, Long userId) {
try {
for (int i = 0; i < data.length; i++) {
SubModule subModule=new SubModule();
subModule.setSubModuleId(data[i]);
UserSubModuleId userSubModuleId = new UserSubModuleId();
userSubModuleId.setSubModuleId(subModule);
userSubModuleId.setUserId(userId);
userSubModuleId.setUserModuleId(moduleSysId);
UserSubModule userSubmodule = new UserSubModule();
userSubmodule = userSubModuleDao.findById(userSubModuleId,
false);
catch (DataAccessException ewmsDataExp) {
LOGGER.error(
"Database Exception while updateSubModuleOrder …Run Code Online (Sandbox Code Playgroud) 这是我的代码段。
MQConfiguration 配置类
@Configuration
public class MQConfiguration {
@Bean
public Receiver receiver() {
return new Receiver();
}
}
Run Code Online (Sandbox Code Playgroud)Receiver 处理接收消息的类
@RabbitListener(queues = "testMQ")
public class Receiver {
@RabbitHandler
public void receive(Message msg){
System.out.println(msg.toString());
}
}
Run Code Online (Sandbox Code Playgroud)这是我发送给RabbitMQ的JSON消息
{
"id": 1,
"name": "My Name",
"description": "This is description about me"
}
Run Code Online (Sandbox Code Playgroud)但是,运行应用程序时出现以下错误消息。
2017-02-28 17:16:35.931 WARN 11828 --- [cTaskExecutor-1] s.a.r.l.ConditionalRejectingErrorHandler : Execution of Rabbit message listener failed.
org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener threw exception
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:872) ~[spring-rabbit-1.7.0.RELEASE.jar:na]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:782) ~[spring-rabbit-1.7.0.RELEASE.jar:na]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:702) ~[spring-rabbit-1.7.0.RELEASE.jar:na]
at …Run Code Online (Sandbox Code Playgroud) 我们同时使用spring-web,并spring-websocket在我们的RCP应用程序,它们都通过转换成捆P2-Maven的插件.下面是我们的应用程序的MANIFEST.MF文件.
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Todo
Bundle-SymbolicName: com.example.e4.rcp.todo;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: EXAMPLE
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.apache.commons.logging;bundle-version="1.2.0",
org.springframework.spring-aop;bundle-version="4.3.3",
org.springframework.spring-beans;bundle-version="4.3.3",
org.springframework.spring-context;bundle-version="4.3.3",
org.springframework.spring-core;bundle-version="4.3.3",
org.springframework.spring-expression;bundle-version="4.3.3",
org.springframework.spring-web;bundle-version="4.3.3",
org.eclipse.e4.ui.css.swt;bundle-version="0.12.0",
org.eclipse.e4.ui.css.swt.theme;bundle-version="0.10.0",
org.eclipse.e4.ui.workbench.addons.swt;bundle-version="1.2.0",
org.eclipse.e4.ui.workbench.renderers.swt;bundle-version="0.13.0",
org.eclipse.e4.ui.workbench.swt;bundle-version="0.13.0",
org.eclipse.swt;bundle-version="3.104.1",
org.eclipse.e4.ui.di;bundle-version="1.1.0",
org.eclipse.e4.core.services;bundle-version="2.0.100",
org.eclipse.osgi.services;bundle-version="3.5.100",
org.eclipse.e4.core.di.annotations;bundle-version="1.5.0",
org.springframework.spring-websocket;bundle-version="4.3.2",
org.springframework.spring-messaging;bundle-version="4.3.2",
javax.inject;bundle-version="1.0.0",
javax.annotation;bundle-version="1.2.0",
org.apache.tomcat.embed.tomcat-embed-core;bundle-version="8.5.4",
org.apache.tomcat.embed.tomcat-embed-websocket;bundle-version="8.5.4"
Run Code Online (Sandbox Code Playgroud)
当我启动应用程序时,它会弹出以下错误:
!SESSION 2016-11-10 09:48:03.750 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_101
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments: -product com.example.e4.rcp.todo.product clearPersistedState
Command-line arguments: -product com.example.e4.rcp.todo.product -data > :\Users\wangzen\Console_prototype/../runtime-todo.product -dev > ile:C:/Users/wangzen/Console_prototype/.metadata/.plugins/org.eclipse.pde.core/to> o.product/dev.properties -os win32 …Run Code Online (Sandbox Code Playgroud) 我有一个基于spring-boot的应用程序,并且pom.xml文件配置如下。
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<includes>
<include>**/IT*.java</include>
<include>**/*IT.java</include>
<include>**/*ITCase.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> …Run Code Online (Sandbox Code Playgroud) java integration-testing maven-failsafe-plugin spring-boot spring-boot-maven-plugin
我有Java代码执行以下操作:
File.createTempFile()File.delete()(我们真的只想生成一个临时文件名)com.google.commons.io.ByteStreams.copy()使用OutputSupplier给定相同文件名的新文件将"模板"ZIP文件复制到同一路径在特定系统上,第4步一致失败FsReadOnlyArchiveFileSystemException - "This is a read-only archive file system!"(参见http://java.net/projects/truezip/lists/users/archive/2011-05/message/9)
调试TrueZIP代码,我注意到以下内容:
以下是您在调试器表达式列表中看到的内容:
fn => "C:/myworkdir/temp/myfile4088293380313057223tmp.zip"
java.nio.file.Files.isWritable(java.nio.file.Paths.get(fn)) => false
new java.io.File(fn).canWrite() => true
Run Code Online (Sandbox Code Playgroud)
使用JDK 1.7.04
有任何想法吗?
比方说,我有一个基于e4平台的应用程序,使用纯JavaFX而不是SWT作为渲染技术,就像这个.它是否间接需要一些SWT库?毕竟,Eclipse平台基于SWT.我理解它是正确的吗?我看不到来自Dependencies选项卡的任何直接依赖关系.
我有一个React应用程序,以下是JavaScript代码
import React from 'react';
import ReactDOM from 'react-dom';
const App = function(){
return <div>Hi</div>
}
ReactDOM.render(<App />, document.querySelector('.container'));
Run Code Online (Sandbox Code Playgroud)
HTML文件如下.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/style/style.css">
<link rel="stylesheet" href="https://cdn.rawgit.com/twbs/bootstrap/48938155eb24b4ccdde09426066869504c6dab3c/dist/css/bootstrap.min.css">
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAq06l5RUVfib62IYRQacLc-KAy0XIWAVs"></script>
</head>
<body>
<div class="container"></div>
</body>
<script src="/bundle.js"></script>
</html>
Run Code Online (Sandbox Code Playgroud)
我不明白的问题是,如果我删除import React from 'react',它将显示如下的错误消息.
未捕获的ReferenceError:未定义React
但我没有在任何地方明确地在我的代码中使用React,为什么它会显示这样的消息.谁能告诉我引擎盖下发生了什么?
更新: 与这个问题不完全相同的问题,因为我在我的代码中只有一个单独的组件,不涉及任何父组件.
java ×6
spring-boot ×3
spring-amqp ×2
algorithm ×1
eclipse ×1
eclipse-rcp ×1
exception ×1
ideavim ×1
javafx ×1
javascript ×1
mockito ×1
nio ×1
osgi ×1
osgi-bundle ×1
python-3.x ×1
rabbitmq ×1
rcp ×1
reactjs ×1
spring ×1
spring-mvc ×1
swt ×1
testng ×1
truezip ×1
writable ×1