This repository was archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
spring_configuring_by_xml
Otávio Santana edited this page Aug 12, 2013
·
1 revision
SpringConfig.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="cassandraFactory" class="org.easycassandra.persistence.cassandra.spring.CassandraFactoryAnnotation">
<constructor-arg name="host" value="localhost" />
<constructor-arg name="keySpace" value="javabahia" />
<property name="annotatedClasses">
<list>
<!-- mapped objects -->
<value>org.javabahia.cassandra.spring.Person</value>
</list>
</property>
@Entity(name = "person")
public class Person implements Serializable {
@Id
private Long id;
@Index
@Column(name = "name")
private String name;
@Column(name = "born")
private Integer year;
//getter and setter
}
public class App
{
public static void main( String[] args )
{
ApplicationContext ctx = new GenericXmlApplicationContext("SpringConfig.xml");
CassandraTemplate cassandraTemplate=(CassandraTemplate)ctx.getBean("cassandraTemplate");
Person person=new Person();
person.setId(1l);
person.setName("Otávio Santana");
person.setYear(25);
cassandraTemplate.save(person);
Person otavio=cassandraTemplate.findOne(1l, Person.class);
cassandraTemplate.delete(1l, Person.class);
cassandraTemplate.deleteAll(Person.class);
}
}