Комментарии:
I am using tomcat10 and jersey version 3.1.3 but not able to avoid this error - SEVERE: MessageBodyWriter not found for media type=application/xml, type=class com.jersey.demorest.Alien, genericType=class com.jersey.demorest.Alien.
ОтветитьHi scuse me for my english. I tried to follow the tutorial but this error appears as soon as I invoke the rest "java.lang.NoClassDefFoundError: jakarta/servlet/Filter".
Tomcat 8 and java 1.8
The configuration is in the pom:
<properties>
<jersey.version>3.1.3</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<war.mvn.plugin.version>3.4.0</war.mvn.plugin.version>
</properties>
<dependencies>
<dependencies>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependencies>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<!-- uncomment this to get JSON support
<dependencies>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>
-->
</dependencies>
web.xml:
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.telusko.demorest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
Help me Thaks
Awesome explanation, seeing this in 2023
ОтветитьIn this video details of RestAPI is just 10% and remaining 90% consist of jersey project creation, Spring project creation, jdbc etc.
Ответить@RestController
@RequestMapping(value = "/employee")
public class EmployeeController {
@Autowired
private EmployeeRep employeeRep;
@GetMapping("/one")
public Map<String, Long> maleAndFemaleEmployees() {
List<Employee> noOfMaleAndFemaleEmployees = employeeRep.findAll();
Map<String, Long> collect = noOfMaleAndFemaleEmployees.stream()
.collect(Collectors.groupingBy(Employee::getGender, Collectors.counting()));
return collect;
}
@GetMapping("/two")
public Stream<String> findAllEmpDeptDistinct() {
List<Employee> findAll = employeeRep.findAll();
Stream<String> distinct = findAll.stream().map(app -> app.getDept()).distinct();
return distinct;
}
@GetMapping("/three")
public Map<String, Double> avgAgeOfMaleAndFemale() {
List<Employee> avgAgeOfMaleAndFemaleEmployees = employeeRep.findAll();
Map<String, Double> collect = avgAgeOfMaleAndFemaleEmployees.stream()
.collect(Collectors.groupingBy(Employee::getGender, Collectors.averagingDouble(Employee::getAge)));
return collect;
}
@GetMapping("/four")
public Optional<Employee> highPaidEmployee() {
List<Employee> highestPaidDetailFull = employeeRep.findAll();
Optional<Employee> max = highestPaidDetailFull.stream()
.collect(Collectors.maxBy(Comparator.comparingDouble(Employee::getSalary)));
return max;
}
@GetMapping("/five")
public ResponseEntity<String> highestPaidEmployee() {
List<Employee> highestPaid = employeeRep.findAll();
Optional<Employee> max = highestPaid.stream().max(Comparator.comparing(Employee::getSalary));
if (max.isPresent()) {
Employee employee = max.get();
String name = employee.getName();
String department = employee.getDept();
String response = "Highest Paid Employee: " + name + " (Department: " + department + ")";
return ResponseEntity.ok(response);
} else {
return ResponseEntity.notFound().build();
}
}
@GetMapping("/six")
public Stream<String> joinedafter2015() {
List<Employee> findAll = employeeRep.findAll();
Stream<String> map = findAll.stream().filter(te -> te.getYearOfJoining() > 2015).map(Employee::getName);
return map;
}
@GetMapping("/seven")
public Map<String, Long> employeeCountByDepartment() {
List<Employee> countByDepartment = employeeRep.findAll();
Map<String, Long> collect = countByDepartment.stream()
.collect(Collectors.groupingBy(Employee::getDept, Collectors.counting()));
return collect;
}
@GetMapping("/eight")
public Map<String, Double> avgSalaryOfDepartments() {
List<Employee> avgSalaryOfDepts = employeeRep.findAll();
Map<String, Double> collect = avgSalaryOfDepts.stream()
.collect(Collectors.groupingBy(Employee::getDept, Collectors.averagingDouble(Employee::getSalary)));
return collect;
}
@GetMapping("/nine")
public Optional<Employee> youngestMaleEmployeeInProductDevelopment() {
List<Employee> youngestMaleEmployeeInProductDeve = employeeRep.findAll();
Optional<Employee> max = youngestMaleEmployeeInProductDeve.stream()
.filter(te -> te.getGender().equals("Male") && te.getDept().equals("Product Development"))
.min(Comparator.comparing(Employee::getAge));
return max;
}
@GetMapping("/ten")
public Optional<Employee> seniorMostEmployee() {
List<Employee> seniorEmployee = employeeRep.findAll();
Optional<Employee> collect = seniorEmployee.stream()
.collect(Collectors.minBy(Comparator.comparing(Employee::getYearOfJoining)));
return collect;
}
@GetMapping("/eleven")
public Map<String, Long> countMaleFemaleEmployeesInSalesMarketing() {
List<Employee> countMaleFemaleEmpInSalesMarketing = employeeRep.findAll();
Map<String, Long> collect = countMaleFemaleEmpInSalesMarketing.stream()
.filter(te -> te.getDept().equals("Sales And Marketing"))
.collect(Collectors.groupingBy(Employee::getGender, Collectors.counting()));
return collect;
}
@GetMapping("/twelve")
public Map<String, Double> avgSalaryOfMaleAndFemaleEmployees() {
List<Employee> avgSalaryOfMaleAndFemaleEmp = employeeRep.findAll();
Map<String, Double> collect = avgSalaryOfMaleAndFemaleEmp.stream()
.collect(Collectors.groupingBy(Employee::getGender, Collectors.averagingDouble(Employee::getSalary)));
return collect;
}
@GetMapping("/thirteen")
public Map<String, List<String>> employeeListByDepartment() {
List<Employee> findAll = employeeRep.findAll();
Map<String, List<String>> collect = findAll.stream().collect(
Collectors.groupingBy(Employee::getDept, Collectors.mapping(Employee::getName, Collectors.toList())));
return collect;
}
@GetMapping("/fourteen")
public String employeeSalarySumAndAvg() {
List<Employee> empSalarySumAndAvg = employeeRep.findAll();
DoubleSummaryStatistics collect = empSalarySumAndAvg.stream()
.collect(Collectors.summarizingDouble(Employee::getSalary));
return "Total Salary = " + collect.getSum() + ", Average Salary = " + collect.getAverage();
}
@GetMapping("/fifteen")
public ResponseEntity<String> partitionEmployeesByAge() {
List<Employee> partitionEmployeesByAge25OldAnd25Young = employeeRep.findAll();
Map<Boolean, List<Employee>> collect = partitionEmployeesByAge25OldAnd25Young.stream()
.collect(Collectors.partitioningBy(te -> te.getAge() > 25));
Set<Entry<Boolean, List<Employee>>> entrySet = collect.entrySet();
String olderEmployeesResponse = "Employees older than 25 years: ";
String youngerEmployeesResponse = "Employees younger than or equal to 25 years: ";
for (Entry<Boolean, List<Employee>> entry : entrySet) {
List<Employee> list = entry.getValue();
for (Employee employee : list) {
String employeeName = employee.getName() + ", ";
if (entry.getKey()) {
olderEmployeesResponse += employeeName;
} else {
youngerEmployeesResponse += employeeName;
}
}
}
String finalResponse = olderEmployeesResponse + "\n" + youngerEmployeesResponse;
return ResponseEntity.ok(finalResponse);
}
@GetMapping("/sixteen")
public ResponseEntity<String> oldestEmployee() {
List<Employee> oldestEmp = employeeRep.findAll();
Optional<Employee> max = oldestEmp.stream().max(Comparator.comparing(Employee::getAge));
if (max.isPresent()) {
Employee employee = max.get();
String dept = employee.getDept();
int age = employee.getAge();
String response1 = "Department : " + dept;
String response2 = "Age : " + age;
String responseBody = response1 + "\n" + response2;
return ResponseEntity.ok(responseBody);
} else {
return ResponseEntity.notFound().build(); // Or any appropriate response for no employees found
}
}
@GetMapping("/seventeen")
public List<String> findAllEmpNamesStartWithA() {
List<Employee> findAll = employeeRep.findAll();
List<String> collect = findAll.stream().filter(te -> te.getName().startsWith("A")).map(Employee::getName)
.collect(Collectors.toList());
return collect;
}
@GetMapping("/eighteen")
public String findAllEmpDeptCount() {
List<Employee> findAll = employeeRep.findAll();
long count = findAll.stream().map(app -> app.getDept()).distinct().count();
return "Total Department : - " + count;
}
@GetMapping("/ninteen")
public String findAllEmpCount() {
List<Employee> allEmpCount = employeeRep.findAll();
Long count = allEmpCount.stream().collect(Collectors.counting());
return "Total Employees: " + count;
}
}
I can not use @RootXmlElement
Ответить"because I love Jason"🙃
Ответитьnice comment
Ответитьnice content
Ответитьthat is tricky . thanks for successfully video
ОтветитьCan you provide tutorials in Telugu step by step ...from spring framework
Ответитьthis is so cringe-worthy
ОтветитьPlease Which app do you use for your screen recording?
Ответитьi dont understand that why he have to talk about servlet in everything instead of the topic of the tutorial,.I was referring spring boot there also he lecture about servlet n all , then i switched to this here also the same thing, everybody here is not from software background here, Please understand this, I have learnt java only with the help of telusko, but while learning advance , its disturbing that he talks more about the topics which everybody might not understand
ОтветитьWhile running time showing (java.lang.ClassNotFoundException:jakarta.servlet.filter) but I have added related dependencies also still not solving the problem...
ОтветитьThank you sir for this tutorial
Ответить