Spring Annotations
Spring Annotations
-------------------
Annotations are used to provide metadata.
JSE
---
@Override
@SupressWarnings
@Deprecated
@Target
@RententionPolicy
@FunctionalInterface.....
JEE
---
@WebServlet
@WebFilter
@Listener etc...
Hibernate -
-----------
@Entity
@Table
@Id
@Column
@OneToMany @OneToOne @ManyToOne @ManyToMany @JoinColumn etc...
Spring Annotations
------------------
@Required
@Autowired
@Qualifier
@Bean
@Scope
@DependsOn
@PostConstruct
@PreDestroy
@Component
@Named
@Inject
@Configuration
Spring MVC Annotations
-----------------------
@Controller
@RestController
@RequestMapping
@RequestBody
@ResponseBody
Develop Spring application to read data from csv file and store data in Database
table.
4) Create Main class to start ioc and read data from File and call Service layer
method by passsing books as a input for service class method.
@Configuration
Beans.xml -------> AppConfig.java
@Autowired
Document / Workbook
Sheet
Row
Row row = sheet.createRow(0);
Cell
Cell cell0 = row.createCell(0);
while(rowIterator.hasNext()){
Row currentRow = rowIterator.next( );
Iterator<Cell> cellIterator = currentRow.cellIterator( );
while(cellIterator.hasNext( )){
Cell currentCell = cellIterator.next ( );
currentCell.getStringCellValue();
}
}
WorkBook
Sheet
Row
Cell
headerRow.createCell(0).setCellValue("S.No");
headerRow.createCell(1).setCellValue("Name");
headerRow.createCell(2).setCellValue("Email");
while(rows.hasNext( )) {
Row row = rows.next ( );
while(cells.hasNext( )) {
Cell cell = cells.next( ) ;
}
}
book id : 1 to 5 chars
12345spring 200.00
101 hibernate25
@Configuration
@ComponentScan(basePackages="com.nit")
@Component
@Controller
@RestController
@Service
@Repository
@Autowired(required=true|false)
@DependsOn
@Bean
@Scope
@Value
@PropertySource(value={"DbConfig.properties","smtp.properties"})
Types of IOC
------------
IOC is a principle which is used to manage and colloborate dependencies among
objects in application.
1) Dependency Injection
- Setter Injection
- Constructor Injection
2) Dependency Pull
- Dependency lookup
- Contextual Dependency pull
-----------------------------------------------
public class MsgServlet implements Servlet{