Pessoal, fiz várias tentativas utilizando as dicas de vocês mas ainda não consegui resolver o problema. O bean é retornado nulo. Alguém pode me explicar passo a passo como devo fazer ???
Alguém me dá mais uma força aí ?
Vou mostrar como eu uso. Também é JSF 1.2 e Spring:
web.xml:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
faces-config.xml:
<application>
<resource-bundle>
<base-name>message</base-name>
<var>msg</var>
</resource-bundle>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
applicationContext.xml:
<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="contextApplicationContextProvider" class="context.ApplicationContextProvider" />
<tx:annotation-driven />
<context:component-scan base-package="*" />
Exemplo de uso:
Bean injetado:
@Component
public class ProjetoDaoImp extends GenericDaoImp<Projeto,Long>
implements ProjetoDao{
@Component
public class ProjetoController {
@Resource
ProjetoDao dao;
[quote=raf4ever]Vou mostrar como eu uso. Também é JSF 1.2 e Spring:
web.xml:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
faces-config.xml:
<application>
<resource-bundle>
<base-name>message</base-name>
<var>msg</var>
</resource-bundle>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
applicationContext.xml:
<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="contextApplicationContextProvider" class="context.ApplicationContextProvider" />
<tx:annotation-driven />
<context:component-scan base-package="*" />
Exemplo de uso:
Bean injetado:
@Component
public class ProjetoDaoImp extends GenericDaoImp<Projeto,Long>
implements ProjetoDao{
@Component
public class ProjetoController {
@Resource
ProjetoDao dao;
[/code][/quote]
raf4ever, o projeto não roda...dá aquele erro: HTTP Status 503...
vou te passar como estão os meus arquivos
web.xml
[code]<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 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-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/welcomeJSF.jsp</welcome-file>
</welcome-file-list>
</web-app>
faces-config.xml
[code]<?xml version=‘1.0’ encoding=‘UTF-8’?>
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config version="1.2"
xmlns="http://java.sun.com/xml/ns/javaee"
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”>
<application>
<resource-bundle>
<base-name>message</base-name>
<var>msg</var>
</resource-bundle>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
[/code]
welcomeJSF.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%--
This file is an entry point for JavaServer Faces application.
--%>
<f:view>
<h:form>
<h:outputText value="Usuário: "/>
<h:inputText value="#{Controle.usuario}"/>
<h:outputText value="Senha: "/>
<h:inputText value="#{Controle.senha}"/>
</h:form>
</f:view>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="contextApplicationContextProvider" class="context.ApplicationContextProvider" />
<tx:annotation-driven />
<context:component-scan base-package="controle" />
</beans>
meu controlador(bean):
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package controle;
import org.springframework.stereotype.Component;
@Component
public class Controle {
private String usuario;
private String senha;
public Boolean login() {
if (getUsuario().equals("admin") && getSenha().equals("admin")) {
return true;
}
return false;
}
public String getSenha() {
if (senha == null) {
senha = "";
}
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public String getUsuario() {
if (usuario == null) {
usuario = "";
}
return usuario;
}
public void setUsuario(String usuario) {
this.usuario = usuario;
}
}
fiz este método login que é chamado pelo commandButton bem simples só para caráter de teste mesmo…
Fiz também a validação do arquivo applicationContext.xml após colocar as configurações que você me passou e ele me retornou o seguinte erro:
The prefix "context" for element "context:component-scan" is not bound. [34]
Ainda precisa de algumas modificações:
Pode retirar esses dois trechos:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
E adapta o cabeçalho do teu applicationContext.xml de acordo com esse:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
[quote=raf4ever]Ainda precisa de algumas modificações:
Pode retirar esses dois trechos:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
E adapta o cabeçalho do teu applicationContext.xml de acordo com esse:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
[/quote]
Cara, parece que está quase dando certo…
agora faltou componente dispatcher, olha a saída da IDE:
Deploying application in domain failed; Error loading deployment descriptors for module [PROJETO] -- There is no web component by the name of dispatcher here.
/home/NetBeansProjects/PROJETO/nbproject/build-impl.xml:713: O módulo não foi implementado.
FALHA NA CONSTRUÇÃO (tempo total: 0 segundos)
Vixe,esse erro eu nunca vi.Tá usando qual servidor de aplicacao?
Glassfish 2.1
Glassfish 2.1[/quote]
É mandatório usar um AS full-stack? Tinha como testar num Tomcat da vida?