Hi!
Ich habe mir mit eine simplen Maven-Archetype ein MyFaces-Projekt erstellt, jenem dann mittels Maven die Spring.jar hinzugefügt
und dann div. Anpassungen (lt. Buch und Internet) durchgeführt, leider gibt es ein Problem:
Hierzu meine web.xml:
und meine faces-config.xml:
sowie meine application-context.xml:
Wo liegt das Problem mit den Meta-Information in der faces-config.xml?
Mit folgender faces-config.xml funktionierts, warum (was ist bei jenen Meta Infos "besser" und könnte es auch mit den von oben funktionieren)?
Ich habe mir mit eine simplen Maven-Archetype ein MyFaces-Projekt erstellt, jenem dann mittels Maven die Spring.jar hinzugefügt
Code:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.4</version>
<scope>runtime</scope>
</dependency>
und dann div. Anpassungen (lt. Buch und Internet) durchgeführt, leider gibt es ein Problem:
Code:
7.05.2008 12:40:30 org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "org.apache.myfaces.webapp.StartupServletContextListener" is already configured for this context. The duplicate definition has been ignored.
27.05.2008 12:40:30 org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "org.apache.myfaces.webapp.StartupServletContextListener" is already configured for this context. The duplicate definition has been ignored.
27.05.2008 12:40:30 org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "org.springframework.web.context.ContextLoaderListener" is already configured for this context. The duplicate definition has been ignored.
27.05.2008 12:40:30 org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "org.springframework.web.context.request.RequestContextListener" is already configured for this context. The duplicate definition has been ignored.
27.05.2008 12:40:30 org.apache.myfaces.shared_impl.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.RENDER_VIEWSTATE_ID' found, using default value true
27.05.2008 12:40:30 org.apache.myfaces.shared_impl.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.STRICT_XHTML_LINKS' found, using default value true
27.05.2008 12:40:30 org.apache.myfaces.shared_impl.config.MyfacesConfig getLongInitParameter
INFO: No context init parameter 'org.apache.myfaces.CONFIG_REFRESH_PERIOD' found, using default value 2
27.05.2008 12:40:30 org.apache.myfaces.shared_impl.config.MyfacesConfig getBooleanInitParameter
INFO: No context init parameter 'org.apache.myfaces.VIEWSTATE_JAVASCRIPT' found, using default value false
27.05.2008 12:40:30 org.apache.myfaces.shared_impl.config.MyfacesConfig createAndInitializeMyFacesConfig
INFO: Starting up Tomahawk on the MyFaces-JSF-Implementation
27.05.2008 12:40:30 org.apache.myfaces.config.FacesConfigurator feedStandardConfig
INFO: Reading standard config META-INF/standard-faces-config.xml
27.05.2008 12:40:30 org.apache.myfaces.config.FacesConfigurator feedClassloaderConfigurations
INFO: Reading config jar:file:/C:/Dokumente und Einstellungen/y0dA/.m2/repository/org/apache/myfaces/tomahawk/tomahawk/1.1.6/tomahawk-1.1.6.jar!/META-INF/faces-config.xml
27.05.2008 12:40:30 org.apache.myfaces.config.FacesConfigurator feedWebAppConfig
INFO: Reading config /WEB-INF/faces-config.xml
27.05.2008 12:40:30 org.apache.myfaces.config.FacesConfigurator logMetaInf
INFO: Starting up MyFaces-package : myfaces-api in version : 1.2.2 from path : file:/C:/Dokumente und Einstellungen/y0dA/.m2/repository/org/apache/myfaces/core/myfaces-api/1.2.2/myfaces-api-1.2.2.jar
27.05.2008 12:40:30 org.apache.myfaces.config.FacesConfigurator logMetaInf
INFO: Starting up MyFaces-package : myfaces-impl in version : 1.2.2 from path : file:/C:/Dokumente und Einstellungen/y0dA/.m2/repository/org/apache/myfaces/core/myfaces-impl/1.2.2/myfaces-impl-1.2.2.jar
27.05.2008 12:40:30 org.apache.myfaces.config.FacesConfigurator logMetaInf
INFO: MyFaces-package : tomahawk-sandbox not found.
27.05.2008 12:40:30 org.apache.myfaces.config.FacesConfigurator logMetaInf
INFO: Starting up MyFaces-package : tomahawk in version : 1.1.6 from path : file:/C:/Dokumente und Einstellungen/y0dA/.m2/repository/org/apache/myfaces/tomahawk/tomahawk/1.1.6/tomahawk-1.1.6.jar
27.05.2008 12:40:30 org.apache.myfaces.shared_impl.util.LocaleUtils toLocale
WARNUNG: Locale name in faces-config.xml null or empty, setting locale to default locale : de_AT
27.05.2008 12:40:31 org.apache.myfaces.config.FacesConfigurator handleSerialFactory
INFO: Serialization provider : class org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory
27.05.2008 12:40:31 org.apache.myfaces.webapp.AbstractFacesInitializer initFaces
INFO: ServletContext 'C:\Entwicklung\projects\Budget\src\main\webapp\' initialized.
27.05.2008 12:40:31 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
27.05.2008 12:40:31 org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
27.05.2008 12:40:31 org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.XmlWebApplicationContext@19a9de2: display name [Root WebApplicationContext]; startup date [Tue May 27 12:40:31 CEST 2008]; root of context hierarchy
27.05.2008 12:40:31 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
27.05.2008 12:40:31 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/faces-config.xml]
27.05.2008 12:40:34 org.springframework.web.context.ContextLoader initWebApplicationContext
SCHWERWIEGEND: Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://java.sun.com/xml/ns/javaee]
Offending resource: ServletContext resource [/WEB-INF/faces-config.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:281)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1250)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1243)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:141)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:423)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:353)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4350)
at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1244)
at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:604)
at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:129)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Hierzu meine web.xml:
Code:
<?xml version="1.0"?>
<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<description>MyProject web.xml</description>
<!--optional: context-param>
<description>Comma separated list of URIs of (additional) faces config files.
(e.g. /WEB-INF/my-config.xml)
See JSF 1.0 PRD2, 10.3.2
Attention: You do not need to put /WEB-INF/faces-config.xml in here.
</description>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/examples-config.xml</param-value>
</context-param-->
<context-param>
<description>
State saving method: "client" or "server" (= default) See
JSF Specification 2.5.3
</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<description>
Only applicable if state saving method is "server" (=
default). Defines the amount (default = 20) of the latest
views are stored in session.
</description>
<param-name>
org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION
</param-name>
<param-value>20</param-value>
</context-param>
<context-param>
<description>
Only applicable if state saving method is "server" (=
default). If true (default) the state will be serialized to
a byte stream before it is written to the session. If false
the state will not be serialized to a byte stream.
</description>
<param-name>
org.apache.myfaces.SERIALIZE_STATE_IN_SESSION
</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
Only applicable if state saving method is "server" (=
default) and if
org.apache.myfaces.SERIALIZE_STATE_IN_SESSION is true (=
default) If true (default) the serialized state will be
compressed before it is written to the session. If false the
state will not be compressed.
</description>
<param-name>
org.apache.myfaces.COMPRESS_STATE_IN_SESSION
</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
This parameter tells MyFaces if javascript code should be
allowed in the rendered HTML output. If javascript is
allowed, command_link anchors will have javascript code that
submits the corresponding form. If javascript is not
allowed, the state saving info and nested parameters will be
added as url parameters. Default: "true"
</description>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>
If true, rendered HTML code will be formatted, so that it is
"human readable". i.e. additional line separators and
whitespace will be written, that do not influence the HTML
code. Default: "true"
</description>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
If true, a javascript function will be rendered that is able
to restore the former vertical scroll on every request.
Convenient feature if you have pages with long lists and you
do not want the browser page to always jump to the top if
you trigger a link or button action that stays on the same
page. Default: "false"
</description>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
Used for encrypting view state. Only relevant for client
side state saving. See MyFaces wiki/web site documentation
for instructions on how to configure an application for
diffenent encryption strengths.
</description>
<param-name>org.apache.myfaces.SECRET</param-name>
<param-value>NzY1NDMyMTA=</param-value>
</context-param>
<context-param>
<description>
Validate managed beans, navigation rules and ensure that
forms are not nested.
</description>
<param-name>org.apache.myfaces.VALIDATE</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
Treat readonly same as if disabled attribute was set for
select elements.
</description>
<param-name>
org.apache.myfaces.READONLY_AS_DISABLED_FOR_SELECTS
</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
Use the defined class as the class which will be called when
a resource is added to the ExtensionFilter handling. Using
StreamingAddResource here helps with performance. If you
want to add custom components and want to use the
ExtensionFilter, you need to provide your custom
implementation here.
</description>
<param-name>org.apache.myfaces.ADD_RESOURCE_CLASS</param-name>
<param-value>
org.apache.myfaces.renderkit.html.util.DefaultAddResource
</param-value>
</context-param>
<context-param>
<description>
Virtual path in the URL which triggers loading of resources
for the MyFaces extended components in the ExtensionFilter.
</description>
<param-name>
org.apache.myfaces.RESOURCE_VIRTUAL_PATH
</param-name>
<param-value>/faces/myFacesExtensionResource</param-value>
</context-param>
<context-param>
<description>
Check if the extensions-filter has been properly configured.
</description>
<param-name>
org.apache.myfaces.CHECK_EXTENSIONS_FILTER
</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
Define partial state saving as true/false.
</description>
<param-name>javax.faces.PARTIAL_STATE_SAVING_METHOD</param-name>
<param-value>false</param-value>
</context-param>
<!-- context parameter -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/faces-config.xml
</param-value>
</context-param>
<!--optional: context-param>
<description>Comma separated list of URIs of (additional) faces config files.
(e.g. /WEB-INF/my-config.xml)
See JSF 1.0 PRD2, 10.3.2
Attention: You do not need to put /WEB-INF/faces-config.xml in here.
</description>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/examples-config.xml</param-value>
</context-param-->
<!-- Extensions Filter -->
<filter>
<filter-name>extensionsFilter</filter-name>
<filter-class>
org.apache.myfaces.webapp.filter.ExtensionsFilter
</filter-class>
<init-param>
<description>
Set the size limit for uploaded files. Format: 10 - 10
bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
</description>
<param-name>uploadMaxFileSize</param-name>
<param-value>100m</param-value>
</init-param>
<init-param>
<description>
Set the threshold size - files below this limit are
stored in memory, files above this limit are stored on
disk.
Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
</description>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>extensionsFilter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>extensionsFilter</filter-name>
<url-pattern>/faces/*</url-pattern>
</filter-mapping>
<!-- Listener, to allow Jetty serving MyFaces apps -->
<listener>
<listener-class>
org.apache.myfaces.webapp.StartupServletContextListener
</listener-class>
</listener>
<!-- Listener, to load Spring Application Context -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- Listener for Spring Beans -->
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!-- Welcome files -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
und meine faces-config.xml:
Code:
<?xml version="1.0"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<!-- managed beans of the simple hello world app -->
<!-- <managed-bean>
<managed-bean-name>helloWorld</managed-bean-name>
<managed-bean-class>org.apache.myfaces.blank.HelloWorldController</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean> -->
<!-- navigation rules for helloWorld.jsp -->
<navigation-rule>
<from-view-id>/helloWorld.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/page2.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<!-- navigation rules for page2.jsp -->
<navigation-rule>
<from-view-id>/page2.jsp</from-view-id>
<navigation-case>
<from-outcome>back</from-outcome>
<to-view-id>/helloWorld.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
sowie meine application-context.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- <bean id="helloWorldController"
class="org.apache.myfaces.blank.HelloWorldController">
</bean> -->
<bean name="helloWorld"
class="org.apache.myfaces.blank.HelloWorldController"
scope="request">
</bean>
</beans>
Wo liegt das Problem mit den Meta-Information in der faces-config.xml?
Mit folgender faces-config.xml funktionierts, warum (was ist bei jenen Meta Infos "besser" und könnte es auch mit den von oben funktionieren)?
Code:
<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
<faces-config>
<application>
<variable-resolver>
org.springframework.web.jsf.DelegatingVariableResolver
</variable-resolver>
<locale-config>
<default-locale>de_DE</default-locale>
<supported-locale>de</supported-locale>
<supported-locale>en</supported-locale>
</locale-config>
</application>
<!-- managed beans of the simple hello world app -->
<!-- <managed-bean>
<managed-bean-name>helloWorld</managed-bean-name>
<managed-bean-class>org.apache.myfaces.blank.HelloWorldController</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean> -->
<!-- navigation rules for helloWorld.jsp -->
<navigation-rule>
<from-view-id>/helloWorld.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/page2.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<!-- navigation rules for page2.jsp -->
<navigation-rule>
<from-view-id>/page2.jsp</from-view-id>
<navigation-case>
<from-outcome>back</from-outcome>
<to-view-id>/helloWorld.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
Zuletzt bearbeitet: