无法使用spring batch

时间:2016-02-10 08:49:54

标签: java xml jdbc cassandra spring-batch

我正在编写一个spring批处理进程来读取cassandra表中的数据并对其进行修改并将数据写回cassandra表。我使用相同的类来读取和写回数据表。我的工作写在一个xml文件中,我正在运行该xml文件本身。我收到以下错误: 当我尝试将ArrayList写回表

时,会显示错误
  

org.springframework.data.cassandra.mapping.VerifierMappingExceptions:   java.util.ArrayList:Cassandra实体必须有@Table,   @Persistent或@PrimaryKeyClass Annotation

它也显示

  

at org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntityMetadataVerifier.verify(BasicCassandraPersistentEntityMetadataVerifier.java:45)       在org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntity.verify(BasicCassandraPersistentEntity.java:198)

的xml:

    <job id="LoadStatusIndicator" job-repository="jobRepository" restartable="false">
        <step id="LoadStatus" next="">
            <tasklet>
                <chunk reader="StatusReader" processor="ItemProcessor" writer="ItemWriter"
                    commit-interval="1" />
            </tasklet>
        </step>
    </job>

    <beans:bean id="ItemWriter" scope="step"
        class="com.batch.writer.ItemWriter">
    </beans:bean>

<beans:bean id="ItemProcessor" scope="step"
        class="com.batch.processor.ItemProcessor">
    </beans:bean>
    <beans:bean id="Reader" scope="step"
        class="com.reader.ItemReader">
        <beans:property name="dataSource" ref="CassandraSource" />

    </beans:bean>

的applicationContext.xml:

<beans:bean id="CassandraSource" parent="DataSourceParent">
<beans:property name="url" value="jdbc:cassandra://${cassandra.hostName}:${cassandra.port}/${cassandra.keyspace}" />
<beans:property name="driverClassName" value="org.apache.cassandra.cql.jdbc.CassandraDriver" />
</beans:bean>

读者类:

 @Override
    public List<Item> read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException 
    {
    List<Item> results = new ArrayList<Item>();
try {
results = cassandraTemplate.select(query,Item.class);
    } catch (Exception e) {
    e.printStackTrace();
    }
return results;
    }

作家类:

@Override
public void write(List<? extends Item> item) throws Exception {
    try {
    cassandraTemplate.update(item);
}catch(Exception e){e.printStackTrace();}

项目类:

@Entity
//@Persistent
//@Transactional
@Table(value ="test")
//@IdClass(ItemPK.class)
//Serializable{
public class Item implements Serializable{

@Id
@PrimaryKeyColumn(name = "id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private Integer id;

@PrimaryKeyColumn(name = "name", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private String name;

@Column(value = "address")
private Float address;

public Item(){}
public Item(Integer id, String name, Float address) {
    super();
    this.id = id;
    this.name = name;
    this.address = address;
}
public Integer getId() {
    return id;
}
public void setId(Integer id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public Float getAddress() {
    return address;
}
public void setAddress(Float address) {
    this.address = address;
}

0 个答案:

没有答案