mdp*_*mdp 4 spring dependency-injection autowired jsf-2 managed-bean
我使用Spring Java邮件和Velocity模板开发了一个电子邮件服务,如下所示.
Email.java
@Component
public class Email {
private JavaMailSender mailSender;
private VelocityEngine velocityEngine;
@Autowired
private ApplReviewService applReviewService;
@Autowired
private UserService userService;
public void setUserService(UserService userService ) {
this.userService=userService;
}
public UserService getuserService() {
return userService;
}
@Autowired
@Required
public void setMailSender(JavaMailSender mailSender) {
this.mailSender = mailSender;
}
public VelocityEngine getVelocityEngine() {
return velocityEngine;
}
@Autowired
@Required
public void setVelocityEngine(VelocityEngine velocityEngine) {
this.velocityEngine = velocityEngine;
}
Run Code Online (Sandbox Code Playgroud)
//发送电子邮件的方法 }
我的Spring.xml
<context:component-scan base-package="com.test.common"/>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
</bean>
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<value>
resource.loader=class
class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
</value>
</property>
</bean>
@ManagedBean(name="person")
@SessionScoped
Public class Person{
@Autowired
private Email email ; // getter and setter for this.
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试将我的Email类自动装入Jsf managedBean但我得到空指针异常.哪里出错了
你不能在JSF托管bean中注入这样的Spring bean.将其更改为
@ManagedBean(name="person")
@SessionScoped
Public class Person{
@ManagedProperty(value="#{email}")
private Email email ; // getter and setter for this.
}
Run Code Online (Sandbox Code Playgroud)
也可以看看:
| 归档时间: |
|
| 查看次数: |
6211 次 |
| 最近记录: |