Spring2.5 Component Scan Not Working in JB 7AS
deepusrp Apr 11, 2012 11:42 AMHello Folks,
I'm using JBoss 7 AS(jboss-as-7.1.0.Final) as my server.
I have 2 questions...
1. I'm using Eclipse Helios SR2. I'm not able to get the proper pluging to have JBOSS AS as my server in eclipse.
I got several sites in net for the plugin, but when i tried to install it says conflicting, and it closes.
Can i add Jboss 7 AS to my eclipse ?
2. I'm using spring 2.5, JSF and hibernate application.
The problem is i have used annotation for component and repository but it is not getting initialized. Basically spring component scanner is not working.
Please find the code snippets:
Web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param>
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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="main.controllerbeans" /> <context:annotation-config /> <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list><value>/WEB-INF/configuration.properties</value></list> </property> </bean> <!-- IMPORTING HIBERNATE SETTINGS --> <import resource="/db-config.xml"/>
Component scan is not working... it seems
db-config.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: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.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass">
            <value>${jdbc.driver.className}</value>
        </property>
        <property name="jdbcUrl">
            <value>${jdbc.url}</value>
        </property>
        <property name="user">
            <value>${jdbc.username}</value>
        </property>
        <property name="password">
            <value>${jdbc.password}</value>
        </property>
    </bean>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <!-- <property name="packagesToScan" value="main.dbentities" /> -->
        
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">false</prop>
            </props>
        </property>
        
        <property name="packagesToScan" value="org.adit.spring.hibernate.entity" />
    
         
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
    <context:annotation-config />
    <tx:annotation-driven />
    
    
    
</beans>
faces-config.xml
<?xml version="1.0"?> <faces-config 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_2_0.xsd" version="2.0"> <application> <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver> </application>
NotificationBean.java
import java.io.Serializable;
import javax.faces.bean.RequestScoped;
import main.dao.NotificationDAO;
import main.dbentities.Notification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component("notificationBean")
@RequestScoped
public class NotificationBean implements Serializable {
    
    private static final long serialVersionUID = -3637354326738964505L;
    @Autowired
    Notification notification;
    
    @Autowired
    public NotificationDAO notificationDao;
    
    public NotificationBean() {
        notification = new Notification();
        //notificationDao = new NotificationDaoImpl();
    }
    public void persist(){
        System.out.println("Persist Method");
        notification.setUserId(111);
        notification.setPriorityId(1);
        notificationDao.save(notification);
    }
In my xhtml page i have a input text box:
<h:inputText id="englishMessageTitle" value="#{notificationBean.notification.notificationTitleEng}" />
And there is submit button:
<h:commandButton class="btn_empty" id="submit" value="#{msg['CreateNotification.Submit']}" action="#{notificationBean.persist}" />
I'm getting the follwoing exception:
javax.el.PropertyNotFoundException: /xhtml/postmessage.xhtml @36,111 value="#{notificationBean.notification.notificationTitleEng}": Target Unreachable, identifier 'notificationBean' resolved to null
 at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
 at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
 at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
 at javax.faces.component.UIInput.validate(UIInput.java:960)
 at javax.faces.component.UIInput.executeValidate(UIInput.java:1233)
 at javax.faces.component.UIInput.processValidators(UIInput.java:698)
Its unable to resolve the bean notificationBean
Following are the Jars that i have in my web-inf/lib:
c3p0-0.9.1.2.jar
commons-collections-3.2.1.jar
commons-dbcp-1.4.jar
dom4j-1.6.1.jar
hibernate-3.2.1.ga.jar
hibernate-annotations-3.4.0.GA.jar
hibernate-commons-annotations-3.1.0.GA.jar
hibernate-core-3.3.2.GA.jar
jboss-el-2.0.1.GA.jar
jsf-api.jar
jsf-impl.jar
jsp-2.1-6.0.2.jar
jstl-api-1.2.jar
jstl-impl-1.2.jar
mysql-connector-java-3.0.17-ga-bin.jar
org.springframework.context-2.5.6.SEC01.jar
org.springframework.core-2.5.6.SEC01.jar
org.springframework.transaction-2.5.6.A.jar
persistence-api-1.0.jar
spring-2.5.6.SEC01.jar
spring-beans-2.5.6.SEC01.jar
Please let me know what is the problem, and let me know if u need any other information.
 
     
     
     
     
     
    