我使用 Python 3.7 将数据存储在 DynamoDB 数据库中,当我尝试将项目写入数据库时遇到以下错误消息:
Float types are not supported. Use Decimal types instead.
Run Code Online (Sandbox Code Playgroud)
我的代码:
ddb_table = my_client.Table(table_name)
with ddb_table.batch_writer() as batch:
for item in items:
item_to_put: dict = json.loads(json.dumps(item), parse_float=Decimal)
# Send record to database.
batch.put_item(Item=item_to_put)
Run Code Online (Sandbox Code Playgroud)
“items”是 Python 字典的列表。如果我打印出“item_to_put”字典的类型,它们都是 str 类型。
预先感谢您的任何帮助。
我正在尝试编写一个JUnit测试用例,用于测试辅助类中的方法.该方法使用REST调用外部应用程序,这是我试图在JUnit测试中模拟的调用.
辅助方法使用Spring的RestTemplate进行REST调用.
在我的测试中,我创建了一个模拟REST服务器并模拟REST模板并将它们实例化为:
@Before
public void setUp() throws Exception {
mockServer = MockRestServiceServer.createServer(helperClass.getRestTemplate());
}
Run Code Online (Sandbox Code Playgroud)
然后我为mock服务器播种,以便在helper方法进行REST调用时它应该返回一个适当的响应:
// response is some XML in a String
mockServer
.expect(MockRestRequestMatchers.requestTo(new URI(myURL)))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
.andRespond(MockRestResponseCreators.withStatus(HttpStatus.OK)
.contentType(MediaType.APPLICATION_XML)
.body(response));
Run Code Online (Sandbox Code Playgroud)
当我运行我的测试时,helper方法从它所做的REST调用中接收一个空响应,并且测试失败.
帮助程序生成的REST URL具有查询参数,如下所示:" http:// server:port/application/resource?queryparam1 = value1&queryparam2 = value2 ".
我已经尝试将带有和不带有查询参数的URL(" http:// server:port/application/resource ")放在"myURL"变量中(以引出匹配以便它返回响应),但是可以不让模拟服务器返回任何东西.
我试过搜索这种代码的例子,但还没有找到任何看起来像我的场景的东西.
Spring版本4.1.7.
在此先感谢您的任何帮助.
我正在使用WebLogic Server版本10.3.6.0,其任务是编写一些脚本来自动部署Java应用程序.
我正在查看weblogic.Deployer的文档但是当我尝试运行它时,我收到以下错误:
Error: Could not find or load main class weblogic.Deployer
Run Code Online (Sandbox Code Playgroud)
我在Server的安装目录的server/bin中运行了setWLSEnv.sh脚本,该目录设置了PATH和CLASSPATH环境变量.我的理解是weblogic.Deployer是server/lib/weblogic.jar的一部分,并且作为CLASSPATH变量的一部分在脚本中设置.
我怎么能找到weblogic.Deployer类的位置?
在此先感谢您的任何帮助.
我已经使用 Spring Framework(版本 5.0.5.RELEASE)在 Java 1.8 类中实现了一个异步方法:
public class ClassToBeTested {
@Autowired
private MyComponent myComponent;
@Async
public void doStuff(List<MyClass> myObjects) {
CompletableFuture<MyResponseObject>[] futureList = new CompletableFuture[myObjects.size()];
int count = 0;
for (MyClass myObject : myObjects) {
futureList[count] = myComponent.doOtherStuff(myObject);
count++;
}
// Wait until all doOtherStuff() calls have been completed
CompletableFuture.allOf(futureList).join();
... other stuff ...
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 JUnit 和 Mockito 测试该类。我已将其设置如下,目的是模拟 doStuff() 方法对组件的调用:
@MockBean
private MyComponent myComponentAsAMock;
@InjectMocks
@Autowired
private ClassToBeTested classToBeTested;
@Test
public void myTest() throws Exception { …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring 2.5.4并且正在创建一个我正在部署到Weblogic上的Java应用程序.
我在我的代码中使用的外部库(包含在我的应用程序生成的WAR文件的WEB-INF/classes目录中)中有一个类.我在代码中为类的对象创建了一个实例变量,并添加了@Autowired注释和getter以及setter.在我的应用程序上下文文件中,我已声明了库类的类型的bean并添加了以下内容:
<context:annotation-config />
<context:component-scan base-package="com.mycompany" />
Run Code Online (Sandbox Code Playgroud)
...为了注册将扫描类并处理注释的AutowiredAnnotationBeanPostProcessor.
当我尝试部署应用程序时,出现以下错误:
java.lang.IllegalStateException: Annotation-specified bean name 'myBean' for bean
class [com.mycompany.package.ClassName] conflicts with existing, non-compatible
bean definition of same name and class [com.mycompany.otherPackage.ClassName]
Run Code Online (Sandbox Code Playgroud)
我认为这是因为库中有一个类与我的应用程序代码中的一个同名(两个类的包名都以"com.mycompany"开头).铌.这不是我添加的课程,而是另一课程.有没有办法在不更改应用程序中类的名称的情况下绕过这个问题?
谢谢你的帮助.
参考http://activemq.apache.org/security.html上的 ActiveMQ 安全文档,我尝试将新用户添加到我的 ActiveMQ 配置中。该用户应该只能看到可用队列的子集。
我做了以下事情:
1)在users.properties中添加条目:
myuser=mypassword
Run Code Online (Sandbox Code Playgroud)
2)在groups.properties中添加条目:
publishers=admin,myuser
consumers=admin,myuser
Run Code Online (Sandbox Code Playgroud)
3) 在broker元素的plugins元素中向activemq.xml添加了一个条目:
<authorizationPlugin>
<map>
<authorizationMap>
<authorizationEntries>
<authorizationEntry queue=">" read="admins" write="admins" admin="admins" />
<authorizationEntry queue="MYQUEUEPREFIX.>" read="consumers" write="publishers" admin="admins" />
</authorizationEntries>
</authorizationMap>
</map>
</authorizationPlugin>
Run Code Online (Sandbox Code Playgroud)
当我重新启动 ActiveMQ 并访问 myServerURL:8161/admin 的管理控制台时,我在提供的“需要身份验证”框中输入新创建的用户名和密码 (myuser/mypassword),但它不允许我访问控制台。我进入的唯一方法是使用已经定义的“admin”用户。
我在 Spring Boot(v.2.2.1.RELEASE)应用程序的 Java 类中有以下代码:
@Inject
private JdbcTemplate jdbcTemplate;
@Inject
private MyRowCallbackHandler myRowCallbackHandler;
public void myMethod() {
jdbcTemplate.query(MY_QUERY, myRowCallbackHandler);
}
Run Code Online (Sandbox Code Playgroud)
JDBC 模板对象是 org.springframework.jdbc.core.JdbcTemplate 的实现,处理程序是 org.springframework.jdbc.core.RowCallbackHandler 的实现。
使用 JUnit 版本 4 和 Mockito,我可以模仿通过查询方法从数据库检索一行或多行,从而调用处理程序的 processRow() 方法吗?
感谢您的任何帮助。
org.hibernate.exception.SQLGrammarException当我针对使用 JPA 和 Spring 的 Java 类运行 JUnit 测试时,出现 Oracle 错误:
ORA-00904: "ALIAS"."COLUMN_NAME": invalid identifier
Run Code Online (Sandbox Code Playgroud)
奇怪的是,JUnit 测试在针对开发数据库运行时有效,但在针对我用于持续集成构建的数据库(它们都是 Oracle 数据库)运行时失败。
因此,这表明后一个 d/b 中有一些缺失或错误。但是,我已经双重(和三次)检查了两个数据库中引用的表是否相同,并且包含错误引用的列 COLUMN_NAME。
更多信息 - JUnit 测试中调用的 DAO Java 类使用 javax.persistence.EntityManager:
MyClass myObject = entityManager.find(MyClass.class, idNumber);
Run Code Online (Sandbox Code Playgroud)
MyClass JPA 实体类映射到 Oracle 表:
@Configurable
@Entity
@Table(name = "MyTable", schema = "MySchema")
public class MyClass implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MY_SEQ")
@SequenceGenerator(name = "MY_SEQ", sequenceName = "MY_SEQ", allocationSize = 1)
@Column(name = "ID")
protected BigDecimal id;
@Column(name = …Run Code Online (Sandbox Code Playgroud) 我有一个 BPEL 流程,它可以捕获任何引发的错误并将它们分配给一个变量:
<assign name="AssignFault">
<copy>
<from>ora:getFaultAsString()</from>
<to>$myVariable</to>
</copy>
</assign>
Run Code Online (Sandbox Code Playgroud)
这会将整个 XML 消息(包括标签)放入变量中:
com.oracle.bpel.client.BPELFault: faultName: {{http://schemas.oracle.com/bpel/extension}remoteFault}
messageType: {{http://schemas.oracle.com/bpel/extension}RuntimeFaultMessage}
parts: {{
summary=<summary>oracle.fabric.common.FabricInvocationException: Unable to access the following endpoint(s): myServer/myService</summary>
,detail=<detail>Unable to access the following endpoint(s): myServer/myService</detail>
,code=<code>404</code>}
Run Code Online (Sandbox Code Playgroud)
有没有办法获取单个元素值,即“摘要”、“详细信息”和“代码”标签中包含的文本值?我想将每个的文本分配给单独的变量,并用它们做不同的事情。
在此先感谢您的帮助。
我有一个 org.springframework.ws.soap.client.SoapFaultClientException 对象。我想获取其中包含的详细信息以用于记录目的,但我发现很难确定如何执行此操作。
exception.getFaultStringOrReason() 方法会给我一个基本的错误信息。但是,我需要获取包含在对象故障详细信息中的更多详细信息。SOAP 响应如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Fault xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode>soap:Client</faultcode>
<faultstring>The values from the client failed to pass validation.</faultstring>
<detail>
<Errors>
<Error reason="Required on input.">
<ErrorLocation>
<Node level="1" name="MyElement"/>
<Node level="2" name="MyField"/>
</ErrorLocation>
<Parameters/>
<StackTrace/>
</Error>
</Errors>
</detail>
</soap:Fault>
Run Code Online (Sandbox Code Playgroud)
我已经遍历了许多 org.springframework.ws.soap.SoapFaultDetailElement 对象,但我无法获取其中包含的详细信息。这能做到吗?
提前感谢您的任何帮助
java ×6
spring ×6
junit ×3
oracle ×3
mockito ×2
annotations ×1
boto3 ×1
bpel ×1
hibernate ×1
jdeveloper ×1
jpa ×1
python ×1
rest ×1
soa ×1
soap ×1
spring-boot ×1
weblogic ×1
weblogic11g ×1
xpath ×1