我必须使用Spring Boot编写批处理服务,该服务读取XML文件作为输入.XML输入的结构如下所示,我无法更改它:
<root>
<parent>
<field1>string</field1>
<field2>string</field2>
<field3>string</field2>
<child>
<fieldA>string</fieldA>
<fieldB>string</fieldB>
</child>
<child>
<fieldA>string</fieldA>
<fieldB>string</fieldB>
</child>
<child>
<fieldA>string</fieldA>
<fieldB>string</fieldB>
</child>
</parent>
</root>
Run Code Online (Sandbox Code Playgroud)
我创建了我的Java类:
public class Parent {
private String field1;
private String field2;
private String field3;
private List<Child> children;
// Getters and setters...
}
public class Child {
private String fieldA;
private String fieldB;
// Getters and setters...
}
Run Code Online (Sandbox Code Playgroud)
以下是我在批量配置类中的读者:
@Bean
public ItemReader<Object> reader(){
StaxEventItemReader<Object> reader = new StaxEventItemReader<Object>();
reader.setResource( new ClassPathResource("input.xml") );
reader.setFragmentRootElementName("parent");
XStreamMarshaller unmarshaller = new XStreamMarshaller();
Map<String, Class> …Run Code Online (Sandbox Code Playgroud) 上下文
我正在尝试使用JPA Repository开发使用Spring Boot的批处理服务.使用两个不同的数据源,我想要在内存数据库中创建与批处理相关的表,这样它就不会污染我的业务数据库.
关于网络上的多个主题,我想出了我的两个数据源的配置:
@Configuration
public class DataSourceConfiguration {
@Bean(name = "mainDataSource")
@Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSource mainDataSource(){
return DataSourceBuilder.create().build();
}
@Bean(name = "batchDataSource")
public DataSource batchDataSource( @Value("${batch.datasource.url}") String url ){
return DataSourceBuilder.create().url( url ).build();
}
}
Run Code Online (Sandbox Code Playgroud)
第一个,mainDataSource使用默认的Spring数据库配置.在batchDataSource定义了一个嵌入式HSQL数据库,其中我想要创建的批量和步骤表.
# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url=jdbc:mariadb://localhost:3306/batch_poc
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.max-age=10000
spring.datasource.initialize=false
# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
spring.jpa.generate-ddl=false
spring.jpa.show-sql=true
spring.jpa.database=MYSQL
# SPRING BATCH (BatchDatabaseInitializer)
spring.batch.initializer.enabled=false
# ----------------------------------------
# PROJECT SPECIFIC PROPERTIES
# ----------------------------------------
# BATCH DATASOURCE
batch.datasource.url=jdbc:hsqldb:file:C:/tmp/hsqldb/batchdb
Run Code Online (Sandbox Code Playgroud)
这是我的批量配置:
@Configuration
@EnableBatchProcessing …Run Code Online (Sandbox Code Playgroud) 我在自定义的grunt任务中遇到了错误.下面我发布了一个与问题相关的简单测试用例:
Gruntfile.js
module.exports = function( grunt ){
grunt.task.registerTask( 'endsWith', 'Test of string.prototype.endsWith', function(){
var value = grunt.option('value');
grunt.log.writeln( typeof value );
grunt.log.writeln( value.endsWith( 'bar' ) );
})
};
Run Code Online (Sandbox Code Playgroud)
测试
> grunt endsWith --value=foobar
Running "endsWith" task
string
Warning: Object foobar has no method 'endsWith' Use --force to continue.
Aborted due to warnings.
Execution Time (2016-02-12 16:15:19 UTC)
Total 12ms
Run Code Online (Sandbox Code Playgroud)
就像grunt无法识别String.proptotype.endsWith函数一样.这是正常的吗?
编辑:我正在使用节点v0.10.4
在我的Angular模块中,我有一个像这样的服务:
myApp.service( 'myService', function(){
this.publicFunction1 = function(){
...
};
this.publicfunction2 = function(){
...
};
function privateFunction(){
...
}
});
Run Code Online (Sandbox Code Playgroud)
在某一点上,我需要从私有函数中调用一个"公共"函数,如下所示:
function somePrivateFunc(){
this.publicFunction1();
...
}
Run Code Online (Sandbox Code Playgroud)
但是'this'元素似乎在私有函数中不可见.我怎么能在里面调用publicFunction1()?
这是一个解决方法,但我想明白这种情况.有人能解释一下这里发生了什么吗?还有更好的方法吗?
myApp.service( 'myService', function(){
var service = this;
this.publicFunction1 = function(){
...
};
this.publicfunction2 = function(){
...
};
function privateFunction(){
service.publicFunction1();
...
}
});
Run Code Online (Sandbox Code Playgroud) 拆分字符串时,使用strings.Split,如果输入字符串为空,则生成的空切片的长度为 1。
package main
import (
"strings"
"fmt"
)
func main() {
emptySlice1 := []string{}
debugSlice( emptySlice1 ) // prints "[], []string, len 0"
someStringToSplit := ""
emptySlice2 := strings.Split(someStringToSplit , " ")
debugSlice( emptySlice2 ) // prints "[], []string, len 1"
}
func debugSlice( s []string ){
fmt.Printf("%v, %T, len %v\n", s, s, len(s))
}
Run Code Online (Sandbox Code Playgroud)
游乐场可以在这里找到:https : //play.golang.org/p/kBYR048UtP_0
这是为什么?如何检查切片内的实际项目数(如果没有len功能)?
javascript ×2
spring ×2
spring-batch ×2
spring-boot ×2
angularjs ×1
go ×1
gruntjs ×1
java ×1
jpa ×1
slice ×1
string ×1
xml ×1