Как выше erreur NullPointerException? - PullRequest
0 голосов
/ 24 марта 2020

Я кодирую приложение в весенней загрузке и спящем режиме, когда я пытаюсь получить информацию от tomcat r, я получаю исключение Null Pointer: мой Как я могу решить эту проблему?

   .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
         :: Spring Boot ::        (v1.2.7.RELEASE)

        2020-03-24 15:06:50.156  INFO 29424 --- [           main] com.ensa.pfaapi.PfaAPI                   : Starting PfaAPI on DESKTOP-OJPLBAS with PID 29424 (C:\Users\king\Desktop\imane\pfa\target\classes started by king in C:\Users\king\Desktop\imane\pfa)
        2020-03-24 15:06:50.204  INFO 29424 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing 

    org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2f8f5f62: startup date [Tue Mar 24 15:06:50 CET 2020]; root of context hierarchy
        2020-03-24 15:06:50.978  INFO 29424 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; 
    factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
        2020-03-24 15:06:51.377  INFO 29424 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
        2020-03-24 15:06:51.791  INFO 29424 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$997e206b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
        2020-03-24 15:06:51.853  INFO 29424 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionAttributeSource' of type [class org.springframework.transaction.annotation.AnnotationTransactionAttributeSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
        2020-03-24 15:06:51.863  INFO 29424 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionInterceptor' of type [class org.springframework.transaction.interceptor.TransactionInterceptor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
        2020-03-24 15:06:51.872  INFO 29424 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.config.internalTransactionAdvisor' of type [class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
        2020-03-24 15:06:52.293  INFO 29424 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
        2020-03-24 15:06:52.476  INFO 29424 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
        2020-03-24 15:06:52.478  INFO 29424 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.28
        2020-03-24 15:06:52.630  INFO 29424 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
        2020-03-24 15:06:52.630  INFO 29424 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2429 ms
        2020-03-24 15:06:53.557  INFO 29424 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
        2020-03-24 15:06:53.563  INFO 29424 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
        2020-03-24 15:06:53.564  INFO 29424 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
        2020-03-24 15:06:53.825  INFO 29424 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2f8f5f62: startup date [Tue Mar 24 15:06:50 CET 2020]; root of context hierarchy
        2020-03-24 15:06:53.871  INFO 29424 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/medias]}" onto public java.util.List<com.ensa.pfaapi.dto.TMedia> com.ensa.pfaapi.controller.PfaAPIController.getAllTMedia()
        2020-03-24 15:06:53.874  INFO 29424 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
        2020-03-24 15:06:53.874  INFO 29424 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
        2020-03-24 15:06:53.907  INFO 29424 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
        2020-03-24 15:06:53.907  INFO 29424 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
        2020-03-24 15:06:53.960  INFO 29424 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
        2020-03-24 15:06:54.208  INFO 29424 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
        2020-03-24 15:06:54.285  INFO 29424 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
        2020-03-24 15:06:54.290  INFO 29424 --- [           main] com.ensa.pfaapi.PfaAPI                   : Started PfaAPI in 4.416 seconds (JVM running for 6.599)
        2020-03-24 15:07:13.649  INFO 29424 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
        2020-03-24 15:07:13.649  INFO 29424 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
        2020-03-24 15:07:13.690  INFO 29424 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 41 ms
        2020-03-24 15:07:13.778 ERROR 29424 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

        java.lang.NullPointerException: null
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:201)
            at com.sun.proxy.$Proxy50.findAll(Unknown Source)
            at com.ensa.pfaapi.sevice.TMediaServiceImpl.getAllMedia(TMediaServiceImpl.java:39)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:201)
            at com.sun.proxy.$Proxy49.getAllMedia(Unknown Source)
            at com.ensa.pfaapi.controller.PfaAPIController.getAllTMedia(PfaAPIController.java:26)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
            at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
            at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
            at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:775)
            at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
            at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
            at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
            at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
            at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
            at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
            at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
            at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
            at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
            at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
            at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
            at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
            at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
            at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
            at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
            at java.lang.Thread.run(Unknown Source)

Файловое приложение .properties

spring.datasource.url = jdbc:mysql://localhost:3306/pfi?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
spring.datasource.username = root
spring.datasource.password = 

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
server.port=8080
spring.jackson.serialization.fail-on-empty-beans=false
spring.jpa.open-in-view=false
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type=TRACE
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1

TMediaService

package com.ensa.pfaapi.sevice;



import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.ensa.pfaapi.dao.ITMediaDAO;
import com.ensa.pfaapi.dto.RPostMedia;
import com.ensa.pfaapi.dto.TMedia;



@Service
public class TMediaServiceImpl implements ITMediaService {

    ArrayList<RPostMedia> lp=new ArrayList<RPostMedia>();



        List<TMedia> mediaList =new ArrayList<>(Arrays.asList(
                new TMedia(1,null, 2,"Rohan", "Rohan", "Rohan", null,lp),
                new TMedia(2, null , 3,"Rohan", "Rohan", "Rohan", null,lp)));

    @Autowired(required = false)
    @Lazy
    private ITMediaDAO daoMed;



    @Override
    public List<TMedia> getAllMedia() {
        // TODO Auto-generated method stub
        return daoMed.findAll();
    }

}

класс ITMediaService

package com.ensa.pfaapi.sevice;

import java.util.List;

import com.ensa.pfaapi.dto.TMedia;

public interface ITMediaService {

    List<TMedia> getAllMedia();

}

класс TMedia

package com.ensa.pfaapi.dto;

import java.io.Serializable;
import javax.persistence.*;
import java.util.Date;
import java.util.List;


@Entity
@Table(name="t_media")
public class TMedia implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    @Temporal(TemporalType.DATE)
    private Date created;

    private int deleted;

    private String mpath;

    private String mtype;

    private String name;

    @Temporal(TemporalType.DATE)
    private Date updated;

    //bi-directional many-to-one association to RPostMedia
    @OneToMany(mappedBy="TMedia")
    private List<RPostMedia> RPostMedias;

    public TMedia() {
    }



    public TMedia(int id, Date created, int deleted, String mpath, String mtype, String name, Date updated,
            List<RPostMedia> rPostMedias)  {
        super();
        this.id = id;
        this.created = created;
        this.deleted = deleted;
        this.mpath = mpath;
        this.mtype = mtype;
        this.name = name;
        this.updated = updated;
        RPostMedias = rPostMedias;
    }



    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Date getCreated() {
        return this.created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public int getDeleted() {
        return this.deleted;
    }

    public void setDeleted(int deleted) {
        this.deleted = deleted;
    }

    public String getMpath() {
        return this.mpath;
    }

    public void setMpath(String mpath) {
        this.mpath = mpath;
    }

    public String getMtype() {
        return this.mtype;
    }

    public void setMtype(String mtype) {
        this.mtype = mtype;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getUpdated() {
        return this.updated;
    }

    public void setUpdated(Date updated) {
        this.updated = updated;
    }

    public List<RPostMedia> getRPostMedias() {
        return this.RPostMedias;
    }

    public void setRPostMedias(List<RPostMedia> RPostMedias) {
        this.RPostMedias = RPostMedias;
    }

    public RPostMedia addRPostMedia(RPostMedia RPostMedia) {
        getRPostMedias().add(RPostMedia);
        RPostMedia.setTMedia(this);

        return RPostMedia;
    }

    public RPostMedia removeRPostMedia(RPostMedia RPostMedia) {
        getRPostMedias().remove(RPostMedia);
        RPostMedia.setTMedia(null);

        return RPostMedia;
    }

}

класс ITmediaDao

package com.ensa.pfaapi.dao;



import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.ensa.pfaapi.dto.TMedia;


@Repository("tmediaDao")
public interface ITMediaDAO extends JpaRepository<TMedia , Integer>{



}

класс PFAAPIController

package com.ensa.pfaapi.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ensa.pfaapi.dto.TMedia;
import com.ensa.pfaapi.sevice.ITMediaService;


@RestController
///@Controller
public class PfaAPIController {

    ///@Autowired(required = true)
    @Autowired
    @Lazy
    ITMediaService tmediaService;

    @RequestMapping("/medias")
    public List<TMedia> getAllTMedia(){
        return tmediaService.getAllMedia();
    }

}

Tomcat Erreur

{
    "timestamp": 1585058833796,
    "status": 500,
    "error": "Internal Server Error",
    "exception": "java.lang.NullPointerException",
    "message": "No message available",
    "path": "/medias"
}

Я кодирую приложение в весенней загрузке и в спящем режиме, когда я пытаюсь получить информацию от tomcat r, которую я получаю исключение Null Pointer: my Как я могу решить эту проблему?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...