JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java Tools  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Re:第一個Spring MVC Web程式 [Re:caterpillar]
elviscat





發文: 21
積分: 2
於 2005-10-04 14:22 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我是用jbuilder 2005來實作的,但是遇到以下幾個問題,設定檔如下所示:
web.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://ww
w.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.su
n.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" ve
rsion="2.4">
  <servlet>
    <servlet-name>tradingapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>tradingapp</servlet-name>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>


tradingapp-servlet.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
  <bean id="portfolioController" class="spring.PortfolioController"></bean>
  <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="urlMap">
      <map>
        <entry key="/portfolio.htm">
          <ref bean="portfolioController"/>
        </entry>
      </map>
    </property>
  </bean>
</beans>


PortfolioController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package spring;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
 
public class PortfolioController implements Controller {
 
    public ModelAndView handleRequest(HttpServletRequest request,
                                      HttpServletResponse response) {
 
        return new ModelAndView("/WEB-INF/jsp/portfolio.jsp");
    }
}


理論上,就是web.xml中的DispatcherServlet會去找到tradingapp-servlet.xml,
再根據tradingapp-servlet.xml中的<bean id="portfolioController" class="sprin
g.PortfolioController"></bean>去找package:spring下的PortfolioController.java

完成依賴注入(大陸的講法)

但是我在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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
C:\Borland\JBuilder2005\jdk1.4\bin\javaw -classpath "C:\Borland\JBuilder20
05\thirdparty\jakarta-tomcat-5.0.27\bin\bootstrap.jar;C:\Borland\JBuilder20
05\jdk1.4\lib\tools.jar"  "-Dcatalina.home=C:/Borland/JBuilder2005/thirdpart
y/jakarta-tomcat-5.0.27"  org.apache.catalina.startup.Bootstrap -config C:\
myProject\Tomcat\conf\server8080.xml start 
2005/10/4 下午 01:48:00 org.apache.coyote.http11.Http11Protocol init
資訊: Initializing Coyote HTTP/1.1 on http-8080
2005/10/4 下午 01:48:00 org.apache.catalina.startup.Catalina load
資訊: Initialization processed in 922 ms
2005/10/4 下午 01:48:00 org.apache.catalina.core.StandardService start
資訊: Starting service Catalina
2005/10/4 下午 01:48:00 org.apache.catalina.core.StandardEngine start
資訊: Starting Servlet Engine: Apache Tomcat/5.0.27
2005/10/4 下午 01:48:00 org.apache.catalina.core.StandardHost start
資訊: XML validation disabled
2005-10-04 13:48:02,718 INFO [org.springframework.web.servlet.Dispatch
erServlet] - <Initializing servlet 'tradingapp'>
2005-10-04 13:48:02,828 INFO [org.springframework.web.servlet.Dispatch
erServlet] - <FrameworkServlet 'tradingapp': initialization started>
2005-10-04 13:48:02,890 INFO [org.springframework.beans.factory.xml.X
mlBeanDefinitionReader] - <Loading XML bean definitions from ServletCont
ext resource [/WEB-INF/tradingapp-servlet.xml]>
2005-10-04 13:48:02,921 ERROR [org.springframework.web.servlet.Dispat
cherServlet] - <Context initialization failed>
org.springframework.beans.factory.BeanDefinitionStoreException: Error reg
istering bean with name 'portfolioController' defined in ServletContext reso
urce [/WEB-INF/tradingapp-servlet.xml]: Bean class [spring.PortfolioControll
er] not found; nested exception is java.lang.ClassNotFoundException: sprin
g.PortfolioController
java.lang.ClassNotFoundException: spring.PortfolioController
  at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassL
oader.java:1340)
  at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassL
oader.java:1189)
  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:219)
  at org.springframework.util.ClassUtils.forName(ClassUtils.java:88)
  at org.springframework.beans.factory.support.BeanDefinitionReaderUtils.c
reateBeanDefinition(BeanDefinitionReaderUtils.java:65)
  at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.
parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:369)
  at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.
parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:335)
  at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.
parseBeanDefinitions(DefaultXmlBeanDefinitionParser.java:266)
  at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.
registerBeanDefinitions(DefaultXmlBeanDefinitionParser.java:186)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.regist
erBeanDefinitions(XmlBeanDefinitionReader.java:246)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadB
eanDefinitions(XmlBeanDefinitionReader.java:163)
  at org.springframework.beans.factory.support.AbstractBeanDefinitionRea
der.loadBeanDefinitions(AbstractBeanDefinitionReader.java:125)
  at org.springframework.beans.factory.support.AbstractBeanDefinitionRea
der.loadBeanDefinitions(AbstractBeanDefinitionReader.java:141)
  at org.springframework.web.context.support.XmlWebApplicationContext.
loadBeanDefinitions(XmlWebApplicationContext.java:126)
  at org.springframework.web.context.support.XmlWebApplicationContext.
loadBeanDefinitions(XmlWebApplicationContext.java:94)
  at org.springframework.context.support.AbstractRefreshableApplicationC
ontext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:89)
  at org.springframework.context.support.AbstractApplicationContext.refre
sh(AbstractApplicationContext.java:268)
  at org.springframework.web.context.support.AbstractRefreshableWebAp
plicationContext.refresh(AbstractRefreshableWebApplicationContext.java:134)
  at org.springframework.web.servlet.FrameworkServlet.createWebApplicat
ionContext(FrameworkServlet.java:305)
  at org.springframework.web.servlet.FrameworkServlet.initWebApplication
Context(FrameworkServlet.java:250)
  at org.springframework.web.servlet.FrameworkServlet.initServletBean(Fra
meworkServlet.java:219)
  at org.springframework.web.servlet.HttpServletBean.init(HttpServletBea
n.java:112)
  at javax.servlet.GenericServlet.init(GenericServlet.java:211)
  at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapp
er.java:1029)
  at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.jav
a:862)
  at org.apache.catalina.core.StandardContext.loadOnStartup(StandardCon
text.java:4013)
  at org.apache.catalina.core.StandardContext.start(StandardContext.jav
a:4357)
  at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
  at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
  at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
  at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)
  at org.apache.catalina.core.StandardService.start(StandardService.java:48
0)
  at org.apache.catalina.core.StandardServer.start(StandardServer.java:231
3)
  at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorI
mpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodA
ccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:324)
  at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:284)
  at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:422)
2005/10/4 下午 01:48:03 org.apache.catalina.core.StandardHost getDeployer
資訊: Create Host deployer for direct deployment ( non-jmx ) 
2005/10/4 下午 01:48:03 org.apache.coyote.http11.Http11Protocol start
資訊: Starting Coyote HTTP/1.1 on http-8080
2005/10/4 下午 01:48:03 org.apache.catalina.startup.Catalina start
資訊: Server startup in 2407 ms


看起來好像是沒有抓到PortfolioController.java的感覺

請問大家有遇到相同的問題嗎!?!?


elviscat edited on 2005-10-04 14:26
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
5509 第一個Spring MVC Web程式 caterpillar 6076 2004-11-01 20:34
4649 Re:第一個Spring MVC Web程式 lthwie 936 2005-05-29 09:57
4612 Re:第一個Spring MVC Web程式 lthwie 898 2005-05-29 12:54
7817 Re:第一個Spring MVC Web程式 elviscat 8509 2005-10-04 14:22
4270 Re:第一個Spring MVC Web程式 elviscat 274 2005-10-18 09:02
4233 Re:第一個Spring MVC Web程式 elviscat 184 2005-10-24 13:36
» JWorld@TW »  Java Tools

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8