前言

在SSH项目中添加一个功能,对工程做了一些修改——配置文件、类,仿照已有的来写,启动Tomcat时,项目报错。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
信息: Loading Spring root WebApplicationContext
AbandonedObjectPool is used (org.apache.commons.dbcp.AbandonedObjectPool@565d9e83)
LogAbandoned: false
RemoveAbandoned: true
RemoveAbandonedTimeout: 160
五月 19, 2016 2:18:10 下午 org.apache.catalina.core.ApplicationContext log
严重: StandardWrapper.Throwable
java.lang.NullPointerException
at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:1003)
at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:955)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:470)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4350)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4659)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

五月 19, 2016 2:18:10 下午 org.apache.catalina.core.StandardContext loadOnStartup
严重: Servlet /webh threw load() exception
java.lang.NullPointerException
at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:1003)
at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:955)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:470)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4350)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4659)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

我首先清空了Tomcat的缓存,错误仍在。然后上Google找,其中 stackoverflow 上有人说是 missing servlet-api.jar in your class path

1) Right click on project
2) Got to java build path
3) Click on add library in right hand side.
4) Choose server run time.
5) Click next and select your tom cat server.
6) Click on finish.

还有人在 CSDN导致这个错误的原因是Service实现缺少@Service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//解决办法
public interface UserDao
{
public List<User> findAll();
}

@Repository
public class UserDaoImpl implements UserDao
{
@Override
public List<User> findAll()
{
return null;
}
}

public interface UserService
{
public List<User> findAll();
}

@Service
public class UserServiceImpl implements UserService
{
@Autowired
private UserDao userDao;

@Override
public List<User> findAll()
{
return userDao.findAll();
}
}

@Controller
@RequestMapping("/user")
public class UserController
{
@Autowired
private UserService userService;

@RequestMapping(value = "findAll")
public void findAll()
{
userService.findAll();
}
}

我依依试过之后,都没有用,该报错的还是报错,我静下心来想想:

  1. 项目没有缺少任何东西,因为新添加的功能的逻辑都是复用已有的逻辑。
  2. 程序没有缺少@Srvice,因为这里没有用注释,而且头一天 Bean 的注入已经实现,项目正常启动。
  3. 距上一次成功启动,我新添了 Struct—config.xml,修改了 web.xml。

我检查了 Struct—config.xml,该文件是复用已有的配置文件,只更改了一个路径,路径无误:

1
2
3
4
<action-mappings>
<action parameter="dispatch" path="/webuser" type="com.infomanager.webuser.action.WebUserAction">
</action>
</action-mappings>

web.xml 新加载了上述配置文件,我仔细看了一遍,过然有错,新加载的配置文件之前没有标记”,”:

1
2
3
4
5
6
7
8
<init-param>
<param-name>config</param-name>
<param-value>
/WEB-INF/struts-config_dep.xml,
/WEB-INF/struts-config_role.xml<!-- 此处结尾少一个","-->
/WEB-INF/struts-config_webuser.xml
</param-value>
</init-param>

我不确定Tomcat启动报错是否由缺少”,”引起,但是至少改正之后可以排除一个因素,重启,OK!

小结

小伙子,做事要仔细!抄都会抄错!