Meaning of Different Annotation
Annotation | Meaning of that Annotion |
---|---|
@SpringBootApplication | |
@Order | To provide our own execution order for multiple runners |
@Component | Creating Object to Our Class |
@Controller | Creating Object to Our Class+Web Application-MVC (HTTP Request) |
@RestController | Creating Object to Our Class+WebServices+JSON/XML |
@Service | Creating Object to Our Class+Transaction Management,Locic,Calculation |
@Repository | Creating Object to Our Class+Database Operation |
@ComponentScan(basePackages = "com.app.test") | externally at stater class, then default rule is ignored/overriden in App Config |
@PropertySource("sunil.properties") | specify the property file name in spring using AppConfig |
@Primary | Select any one child manually using by adding at child level class |
@Qualifier("childObject") | Select Manually one Child Object,if multiple Object |
Controller Level Annotation | |
@Controller | Creating Object to Our Class+Web Application-MVC (HTTP Request) |
@RequestMapping("/registrationcontroller") | If there are multiple controller the you need to specify the controller name |
@GetMapping("/register") | |
@PostMapping("/save") | |
@Autowired StudentRepository repo; |
To Create Instance Variables or inject a object |
@Data @AllArgsConstructor @NoArgsConstructor |
Lombok Annotation to generater No Argument Constructor, All argument constructor and generate geter seter annotation |
Model Level Annotation: | |
@Entity @Table(name="Student") |
Create table name "Student" in Database |
@Id @GeneratedValue @Column(name="sid") private int id; |
Create Field "sid" with primary key and autogenerated . |
Model Level Collection Mapping Annotation: | |
@ElementCollection @CollectionTable(name="Client", joinColumns = @JoinColumn(name="sid") ) @Column(name="client") private Set empClient; |
Set Collection Mapping, Create another table "client" with Forign key "sid" |
@ElementCollection private List empLangs; |
List Collection Mapping, Create another table "language" with Forign key "sid" |
@ElementCollection |
Map Collection Mapping, Create another table "client" with Forign key "sid" |
Model Level Association Mapping Annotation: |
|
|
|
JUNIT Annotation |
|
@TestMethodOrder(OrderAnnotation.class) |
We can define multiple test methods inside Testcase.Those are executed in Random order by default. |
@Order(5) |
We can specify our own order using @TestMethodOrder + OrderAnnotation Here we need to provide @Order(number). |
@DisplayName("Description") |
This annotation is used to provide 'Readable text' inplace of actual method and class names at JUnit console. |
@RepeatedTest(value=3) |
|
@BeforeAll |
To execute any logic once per test case before starting. |
@AfterAll |
To execute any logic once per test case after finishing. |
@BeforeEach |
To execute any logic once per test method before starting test method. |
@AfterEach |
To execute any logic once per test method after finishing test method. |
@Disabled |
This annotation is used to specify Ignore one Test-method while executing test-case (do not execute test method) |
@Tag |
These are used to filter test methods for execution in different environments. |
@RepeatedTest |
To execute any test method multiple time (like batch processing) using @RepeatedTest annotation. |
public void testMultiple(TestInfo info) { } |
To know our Test case details like classname,method name, display name,tag name etc we can use one interface TestInfo. |
application.properties file # Default Port:8080 # View Resolver details spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.jpa.show-sql=true |
|
|
|
|
|
|
No Comments Yet!!