spring mvc 500错误Allocate exception for servlet AppService javax.naming.NamingException: Cannot create resource instance 竟是@Resource的原因

时间:2022-03-08 16:13:35

头几天已经测试的完毕了,换了个目录出现这个问题

严重: Allocate exception for servlet AppService
javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.FactoryBase.getObjectInstance(FactoryBase.java:96)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:847)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:158)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:835)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:172)
    at org.apache.catalina.core.DefaultInstanceManager.lookupFieldResource(DefaultInstanceManager.java:585)
    at org.apache.catalina.core.DefaultInstanceManager.processAnnotations(DefaultInstanceManager.java:485)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:174)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1085)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:811)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)

其中好像懂了web.xml过滤,过滤的文件名也不是上边那个文件,再说servlet 异步webservlet  也不需要再web.xml配置过滤 所以不应该是web.xml问题

网上有个帖子说

通过右键菜单,有一次我新建HttpServlet是从New --> Class创建的,但这种操作是隐藏问题的。

      正确的创建方式通过New --> Servlet来创建。

      也就是说,新建HttpServlet的时候,不要从 New --> Class来创建,而是要直接从New --> Servlet来创建!!
---------------------
spring mvc 500错误Allocate exception for servlet AppService javax.naming.NamingException: Cannot create resource instance 竟是@Resource的原因

然后

spring mvc 500错误Allocate exception for servlet AppService javax.naming.NamingException: Cannot create resource instance 竟是@Resource的原因

 

 发现一个亮点 

spring mvc 500错误Allocate exception for servlet AppService javax.naming.NamingException: Cannot create resource instance 竟是@Resource的原因

我这个文件夹内有好几个这种异步请求的文件,看来是这里存在命名冲突

spring mvc 500错误Allocate exception for servlet AppService javax.naming.NamingException: Cannot create resource instance 竟是@Resource的原因

我的虽然不是那样配置的项目里边也有,看来不是这里问题.

经过新建 一个空的servlet 文件    注解@WebServlet(value="/KAppPostBroadCastAsync",asyncSupported=true) 只加了支持异步的功能

请求发现不存在问题,一行一行加入,下边代码导致

@Resource

OpHistoryService ophistoryservice;   java 基础还是不足啊,日改成下边,不报原先的错了

@Autowired
OpHistoryService ophistoryservice;
@Autowired
BroadcastStatService broadcastStatService;