spring - writable - ヌル に 解決 され まし た
BeanをJSFマネージドBeanにオートワイヤリングするときのNULLポインタ (1)
私はSpring JavaメールとVelocity Templateを使って下記のような電子メールサービスを開発しました。
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;
}
//電子メールを送信する方法。 }
My 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.
}
Jsf managedBeanにメールクラスをautowireしようとしていますが、nullポインタ例外が発生しています。 私が間違っているところ。
JSFマネージドBeanにそのようなSpring Beanを挿入することはできません。 それに変更する
@ManagedBean(name="person")
@SessionScoped
Public class Person{
@ManagedProperty(value="#{email}")
private Email email ; // getter and setter for this.
}
参照: