我正在使用jetty 6.1.26作爲web服務器的掛毯,spring,hibernate web-app,並且我無法擺脫userDao bean的nullpointexception(它在application_context_dao.xml ::Spring bean爲空
public class UserManagerImpl implements UserManager {
private UserDao userDao;
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
public boolean checkLogin (String login, String password) {
return userDao.checkLogin(login, password);
}
application_context_dao.xml:
<beans>
<bean id="userDao" class="org.prikic.projektni.domain.dao.hibernate3.UserDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- sessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionProxy" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED, readOnly</prop>
</props>
</property>
</bean>
的web.xml:
<web-app>
<display-name>projektni Tapestry 5 Application</display-name>
<context-param>
<!-- The only significant configuration for Tapestry 5, this informs Tapestry
of where to look for pages, components and mixins. -->
<param-name>tapestry.app-package</param-name>
<param-value>org.prikic.projektni</param-value>
</context-param>
<!-- Specify some additional Modules for two different execution modes:
development and qa. Remember that the default execution mode is production -->
<context-param>
<param-name>tapestry.development-modules</param-name>
<param-value>
org.prikic.projektni.services.DevelopmentModule
</param-value>
</context-param>
<context-param>
<param-name>tapestry.qa-modules</param-name>
<param-value>
org.prikic.projektni.services.QaModule
</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/application_context_dao.xml
/WEB-INF/application_context.xml
<!-- classpath:application_context*.xml -->
</param-value>
</context-param>
<filter>
<filter-name>app</filter-name>
<!-- Special filter that adds in a T5 IoC module derived from the Spring
WebApplicationContext. -->
<filter-class>org.apache.tapestry5.spring.TapestrySpringFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>app</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
任何幫助,將不勝感激......
我不把其他彈簧應用上下文xml文件道歉,那就是:
application_context.xml:
<beans>
<bean id="userManagerTarget" class="org.prikic.projektni.services.impl.UserManagerImpl">
<property name="userDao">
<ref bean="userDao" />
</property>
</bean>
<bean id="userManager" parent="transactionProxy">
<property name="target">
<ref bean="userManagerTarget"/>
</property>
<property name="transactionAttributeSource">
<bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
</property>
</bean>
</beans>
Index.java:
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Service;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.beaneditor.Validate;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.prikic.projektni.services.UserManager;
public class Index {
private static final String BAD_CREDENTIALS = "Bad login and/or password. Please retry.";
//private boolean error = false;
@Persist
private boolean error;
@SessionState(create=false)
private String login;
@Inject
@Service("userManager")
private UserManager userManager;
private String password;
public String getLogin() {
return login;
}
@Validate("required")
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public String getErrorMessage() {
String ret = null;
if (error) {
ret = BAD_CREDENTIALS;
}
return ret;
}
@Validate("required")
public void setPassword(String password) {
this.password = password;
}
String onSuccess() {
String ret = "Index";
error = true;
boolean s = userManager.checkLogin(login, password);
if (s) {
error = false;
ret = "Home";
}
return ret;
}
}
UserManagerImpl bean在哪裏定義?你如何獲得UserManagerImpl的實例? – 2011-12-18 12:29:38
application_context.xml – Borislav 2011-12-18 13:56:18