public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "spring-configuration/serialization-spring-configuration.xml"); Employee employee = (Employee) context.getBean("employee"); // Employee employee = new Employee();//I don't need this line any more, // since I quickly set up a component-scan using Spring to auto wire // this employee bean for me, this is so cool! I feel so at home with // Spring dependency injection now! Praise the Lord!a employee.setName("Steve Sun"); employee.setAge(26); employee.setAddress("1860 Charmeran Ave, San Jose, USA."); employee.setSSN(12345678); employee.setSalary(103000); try { FileOutputStream fos = new FileOutputStream(FILE_DIRECTORY); ObjectOutputStream ous = new ObjectOutputStream(fos); ous.writeObject(employee); ous.close(); fos.close(); System.out.println("Serialized data is saved in " + FILE_DIRECTORY + "."); } catch (IOException e) { e.printStackTrace(); } }
public void test() { Employee emp1 = new EmployeeImpl(); emp1.setFirstName("Kevin"); emp1.setLastName("Moore"); emp1.setGender("Male"); emp1.setAge(30); Address add = new AddressImpl(); add.setStreet("600 Chromakey Dr."); add.setCity("Roswell"); add.setState("NM"); add.setCountry("USA"); add.setPostalCode("21872"); Cubicle cube1 = new CubicleImpl(); cube1.setLength(7.7f); cube1.setWidth(12.2f); cube1.setHeight(5.0f); emp1.setAddress(add); cube1.setEmployee(emp1); ((DatabaseSession) getSession()).insertObject(add); getAbstractSession().insertObject(cube1); // Employee is private owned so should be inserted along with Cubicle. }
@Bean public Employee Ramesh() { Employee ramesh = new Employee(); ramesh.setAge(34); ramesh.setDeptId(2300); ramesh.setEmpNo(3456); ramesh.setName("Sitaram yechuri"); ramesh.setPost("PM"); return ramesh; }