首页 新闻 会员 周边 捐助

SpringMVC模式下的登陆跑不起来

0
[待解决问题]

之前一直用的是myeclipse做开发,最近公司要求使用eclipse。经常遇到myeclipse可以跑起来的项目在eclipse上面出问题。麻烦有这方面的经验的高手指导一下,谢谢。下面我把代码贴出来

 

Web页面的报错

1 description The server encountered an internal error that prevented it from fulfilling this request.

 

控制台的报错

 1 严重: Context initialization failed
 2 org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:\workspace\eclipse\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Contact\WEB-INF\classes\com\cmbc\controller\ContactController.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [D:\workspace\eclipse\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Contact\WEB-INF\classes\com\cmbc\controller\ContactController.class]; nested exception is java.lang.IllegalArgumentException
 3     at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:281)
 4     at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)
 5     at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
 6     at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
 7     at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438)
 8     at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
 9     at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
10     at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
11     at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
12     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
13     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
14     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
15     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
16     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
17     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
18     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
19     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
20     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
21     at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
22     at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
23     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
24     at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
25     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599)
26     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
27     at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518)
28     at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459)
29     at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
30     at javax.servlet.GenericServlet.init(GenericServlet.java:158)
31     at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
32     at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
33     at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864)
34     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
35     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
36     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
37     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
38     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
39     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
40     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
41     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
42     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
43     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
44     at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
45     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
46     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
47     at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
48     at java.lang.Thread.run(Unknown Source)
49 Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [D:\workspace\eclipse\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Contact\WEB-INF\classes\com\cmbc\controller\ContactController.class]; nested exception is java.lang.IllegalArgumentException
50     at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:56)
51     at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
52     at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
53     at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:257)
54     ... 45 more
55 Caused by: java.lang.IllegalArgumentException
56     at org.springframework.asm.ClassReader.<init>(Unknown Source)
57     at org.springframework.asm.ClassReader.<init>(Unknown Source)
58     at org.springframework.asm.ClassReader.<init>(Unknown Source)
59     at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:53)
60     ... 48 more

 

Web.xml配置

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="3.0" 
 3         xmlns="http://java.sun.com/xml/ns/javaee"
 4         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 6     <servlet>
 7         <servlet-name>springmvc</servlet-name>
 8         <servlet-class>
 9             org.springframework.web.servlet.DispatcherServlet
10         </servlet-class>
11         <init-param>
12             <param-name>contextConfigLocation</param-name>
13             <param-value>/WEB-INF/config/springmvc-config.xml</param-value>
14         </init-param>
15         <load-on-startup>1</load-on-startup>    
16     </servlet>
17 
18     <servlet-mapping>
19         <servlet-name>springmvc</servlet-name>
20         <url-pattern>/</url-pattern>
21     </servlet-mapping>
22 </web-app>

 

springmvc-config.xml配置

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:p="http://www.springframework.org/schema/p"
 5     xmlns:mvc="http://www.springframework.org/schema/mvc"
 6     xmlns:context="http://www.springframework.org/schema/context"
 7     xsi:schemaLocation="
 8         http://www.springframework.org/schema/beans
 9         http://www.springframework.org/schema/beans/spring-beans.xsd
10         http://www.springframework.org/schema/mvc
11         http://www.springframework.org/schema/mvc/spring-mvc.xsd     
12         http://www.springframework.org/schema/context
13         http://www.springframework.org/schema/context/spring-context.xsd">
14         
15     <context:component-scan base-package="com.cmbc.controller"/>
16     <context:component-scan base-package="com.cmbc.service"/>
17     <context:component-scan base-package="com.cmbc.dao"/>
18      
19     <mvc:annotation-driven/>
20     <mvc:resources mapping="/css/**" location="/css/"/>
21     <mvc:resources mapping="/*.html" location="/"/>
22     
23     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
24         <property name="prefix" value="/WEB-INF/jsp/"/>
25         <property name="suffix" value=".jsp"/>
26     </bean>
27     
28 </beans>

 

DAO实现类,已经测试过没有问题

  1 package com.cmbc.dao;
  2 
  3 import java.sql.ResultSet;
  4 import java.sql.SQLException;
  5 import java.util.ArrayList;
  6 import java.util.Date;
  7 import java.util.List;
  8 
  9 import org.springframework.stereotype.Repository;
 10 
 11 import com.cmbc.domain.Contact;
 12 import com.cmbc.util.DBCon;
 13 
 14 @Repository
 15 public class ContactDAOImpl implements ContactDAO{
 16 
 17     DBCon dbCon = new DBCon();
 18     
 19     @Override
 20     public List<Contact> getContacts() {
 21         // TODO Auto-generated method stub
 22         String sql = "SELECT id,name,password,birth FROM contact";
 23         ResultSet resultSet = dbCon.query(sql);
 24         Contact contact = null;
 25         List<Contact> contacts = new ArrayList<Contact>();
 26         try {
 27             while (resultSet.next()) {
 28                 
 29                 int id = resultSet.getInt("id");
 30                 String name = resultSet.getString("name");
 31                 String password = resultSet.getString("password");
 32                 Date birth = resultSet.getDate("birth");
 33                 contact = new Contact();
 34                 contact.setBirth(birth);
 35                 contact.setId(id);
 36                 contact.setName(name);
 37                 contact.setPassword(password);
 38                 contacts.add(contact);
 39             }
 40         } catch (SQLException e) {
 41             // TODO Auto-generated catch block
 42             e.printStackTrace();
 43         }
 44         dbCon.closeAll();
 45         return contacts;
 46     }
 47 
 48     @Override
 49     public Contact getContact(int id) {
 50         // TODO Auto-generated method stub
 51         String sql = "SELECT id,name,password,birth FROM contact where id = ?";
 52         ResultSet resultSet = dbCon.query(sql, id);
 53         Contact contact = null;
 54         try {
 55             while (resultSet.next()) {
 56                 int idd = resultSet.getInt("id");
 57                 String name = resultSet.getString("name");
 58                 String password = resultSet.getString("password");
 59                 Date birth = resultSet.getDate("birth");
 60                 contact = new Contact();
 61                 contact.setBirth(birth);
 62                 contact.setId(idd);
 63                 contact.setName(name);
 64                 contact.setPassword(password);
 65             }
 66         } catch (SQLException e) {
 67             // TODO Auto-generated catch block
 68             e.printStackTrace();
 69         }
 70         dbCon.closeAll();
 71         return contact;
 72     }
 73 
 74     @Override
 75     public boolean update(Contact contact) {
 76         // TODO Auto-generated method stub
 77         String sql = "UPDATE contact SET name=?, password=?, birth=? WHERE id=?";
 78         Object obj[] = {contact.getName(),contact.getPassword(),contact.getBirth(),contact.getId()};
 79         int i = dbCon.update(sql, obj);
 80         dbCon.closeAll();
 81         if (i == -1 ) {
 82             return false;
 83         }
 84         return true;
 85     }
 86 
 87     @Override
 88     public boolean save(Contact contact) {
 89         // TODO Auto-generated method stub
 90         String sql = "INSERT INTO contact (name,password,birth) VALUES (?,?,?)";
 91         Object obj[] = {contact.getName(),contact.getPassword(),contact.getBirth()};
 92         int i = dbCon.update(sql, obj);
 93         dbCon.closeAll();
 94         if (i == -1) {
 95             return false;
 96         }
 97         return true;
 98     }
 99 
100     @Override
101     public boolean delete(int id) {
102         // TODO Auto-generated method stub
103         String sql = "DELETE FROM contact WHERE id = ?";
104         int i = dbCon.update(sql, id);
105         dbCon.closeAll();
106         if (i == -1) {
107             return false;
108         }
109         return true;
110     }
111 
112     @Override
113     public Contact queryByNamePassword(String name, String password) {
114         // TODO Auto-generated method stub
115         String sql = "SELECT id,name,password,birth FROM contact where name = ? and password = ?";
116         ResultSet resultSet = dbCon.query(sql, name,password);
117         Contact contact = null;
118         try {
119             while (resultSet.next()) {
120                 int idd = resultSet.getInt("id");
121                 String name2 = resultSet.getString("name");
122                 String password2 = resultSet.getString("password");
123                 Date birth = resultSet.getDate("birth");
124                 contact = new Contact();
125                 contact.setBirth(birth);
126                 contact.setId(idd);
127                 contact.setName(name2);
128                 contact.setPassword(password2);
129             }
130         } catch (SQLException e) {
131             // TODO Auto-generated catch block
132             e.printStackTrace();
133         }
134         dbCon.closeAll();
135         return contact;
136     }
137 
138 }

 

Service实现类

 1 package com.cmbc.service;
 2 
 3 import java.util.List;
 4 
 5 import org.springframework.beans.factory.annotation.Autowired;
 6 import org.springframework.stereotype.Service;
 7 
 8 import com.cmbc.dao.ContactDAO;
 9 import com.cmbc.domain.Contact;
10 @Service
11 public class ContactServiceImpl implements ContactService{
12 
13     @Autowired
14     private ContactDAO contactDAO;
15     
16     @Override
17     public List<Contact> getContacts() {
18         // TODO Auto-generated method stub
19         return contactDAO.getContacts();
20     }
21 
22     @Override
23     public Contact getContact(int id) {
24         // TODO Auto-generated method stub
25         return contactDAO.getContact(id);
26     }
27 
28     @Override
29     public boolean update(Contact contact) {
30         // TODO Auto-generated method stub
31         return contactDAO.update(contact);
32     }
33 
34     @Override
35     public boolean save(Contact contact) {
36         // TODO Auto-generated method stub
37         return contactDAO.save(contact);
38     }
39 
40     @Override
41     public boolean delete(int id) {
42         // TODO Auto-generated method stub
43         return contactDAO.delete(id);
44     }
45 
46     @Override
47     public Contact login(String name, String password) {
48         // TODO Auto-generated method stub
49         return contactDAO.queryByNamePassword(name, password);
50     }
51 
52 }

 

Controller类

 1 package com.cmbc.controller;
 2 
 3 import org.apache.commons.logging.Log;
 4 import org.apache.commons.logging.LogFactory;
 5 import org.springframework.beans.factory.annotation.Autowired;
 6 import org.springframework.stereotype.Controller;
 7 import org.springframework.ui.Model;
 8 import org.springframework.web.bind.annotation.ModelAttribute;
 9 import org.springframework.web.bind.annotation.RequestMapping;
10 
11 import com.cmbc.domain.Contact;
12 import com.cmbc.service.ContactService;
13 
14 @Controller
15 public class ContactController {
16 
17     private Log logger = LogFactory.getLog(ContactController.class);
18     
19     @Autowired
20     private ContactService contactService;
21     
22     @RequestMapping(value="/contact_login_form")
23     public String contactForm(Model model){
24         logger.info("contactForm method invoked");
25         model.addAttribute("contact",new Contact());
26         return "loginForm";
27     }
28     
29     
30     
31     @RequestMapping(value="/contact_login")
32     public String login(@ModelAttribute Contact contact,Model model){
33         logger.info("login method invoked");
34         Contact contact2 = contactService.login(contact.getName(), contact.getPassword());
35         if (contact2 != null) {
36             model.addAttribute("contact2",contact2);
37             return "contactDetail";
38         }
39         return "error";
40     }
41 }

loginForm.jsp

 1 <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
 2 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 3 <%@ page language="java" contentType="text/html; charset=UTF-8"
 4     pageEncoding="UTF-8"%>
 5 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 6 <html>
 7 <head>
 8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 9 <title>Insert title here</title>
10 </head>
11 <body>
12 
13 <form:form commandName="contact" action="contact_login" method="post">
14     name:<form:input path="name"/><br>
15     password:<form:input path="password"/><br>
16     <input type="submit" value="login" />
17 </form:form>
18 
19 </body>
20 </html>

contactDetail.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 
11 name:${contact2.name }<br>
12 password:${contact2.password }<br>
13 </body>
14 </html>


我把eclipse项目里面的代码还有配置文件拷贝到myeclipse里面,就可以正常跑起来。所以这是什么问题有没有人清楚呢,麻烦告知。感激不尽


远歌的主页 远歌 | 菜鸟二级 | 园豆:210
提问于:2016-04-09 21:27
< >
分享
所有回答(1)
0

运行的JDK估计不一样吧

2012 | 园豆:21645 (高人七级) | 2016-04-12 08:41

JDK是一样的,在同一台电脑上面

支持(0) 反对(0) 远歌 | 园豆:210 (菜鸟二级) | 2016-04-12 15:29

@远歌: myeclipse eclipse有时使用自己内含的JDK,比较下看看;要不就是CLASSPATH不一样

支持(0) 反对(0) 2012 | 园豆:21645 (高人七级) | 2016-04-13 08:37

@2012: 因为之前用的是myeclipse做开发,基本上没有接触过eclipse。所以对这个东西不了解

支持(0) 反对(0) 远歌 | 园豆:210 (菜鸟二级) | 2016-04-14 11:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册