IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

[Spring] Envoi de mails


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Mars 2007
    Messages
    179
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 179
    Par défaut [Spring] Envoi de mails
    Bonjour
    J'ai une application J2EE avec un serveur JBoss et un client Swing. Le server-side va avoir besoin d'envoyer des mails avec des attachements en PDF.
    J'ai donc essayé de passer par l'implémentation Spring de JavaMail (JavaMailSenderImpl).

    J'ai donc défini ce bean dans un fichier applicationContext-mail.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    <beans>
        <bean id="javaMailSenderImpl" class="org.springframework.mail.javamail.JavaMailSenderImpl">
            <property name="host">
                <value>10.0.1.2</value>
            </property>
        </bean>
    </beans>
    Et je référence ce bean dans mon applicationContext.xml (pour le service qui va envoyer des mails)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
    <!-- IncidentService Service Proxy with inner IncidentService Service Implementation -->
        <bean id="incidentService" class="org.springframework.aop.framework.ProxyFactoryBean">
            <property name="target">
                <bean class="com.thalys.opalys.business.IncidentServiceImpl">
                    <property name="javaMailSenderImpl"><ref bean="javaMailSenderImpl"/></property>
                </bean>
            </property>
            <property name="proxyInterfaces">
                <value>com.thalys.opalys.business.IncidentService</value>
            </property>
            <property name="interceptorNames">
                <list>
                    <value>hibernateInterceptor</value>
                </list>
            </property>
        </bean>
    Et enfin dans mon beanRefFactory.xml, je référence bien tous les appContext utilisés:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
    <beans>
     
        <bean id="beanRefFactory"
             class="org.springframework.context.support.ClassPathXmlApplicationContext">
            <constructor-arg>
               <list>
                    <value>applicationContext.xml</value>
                    <value>applicationContext-dataSource.xml</value>
                    <value>applicationContext-quartz.xml</value>
                    <value>applicationContext-mail.xml</value>
               </list>
            </constructor-arg>
        </bean>
     
        <bean id="beanRefFactoryEjb"
             class="org.springframework.context.support.ClassPathXmlApplicationContext">
            <constructor-arg>
               <list>
                    <value>applicationContext-localEjb.xml</value>
                    <!-- beanRefFactoryEjb merge-point -->
               </list>
            </constructor-arg>
        </bean>
        <!-- beanRefFactoryEjbXml merge-point -->
     
    </beans>
    A la compiltion (Maven), tout se passe bien, mais au déploiement, j'ai une erreur, qui est la suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    09:47:42,080 ERROR [ContextLoader] Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'incidentService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot create inner bean 'com.thalys.opalys.business.IncidentServiceImpl#5363a8' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.thalys.opalys.business.IncidentServiceImpl#5363a8' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'javaMailSenderImpl' while setting bean property 'javaMailSenderImpl'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'javaMailSenderImpl' is defined
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.thalys.opalys.business.IncidentServiceImpl#5363a8' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'javaMailSenderImpl' while setting bean property 'javaMailSenderImpl'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'javaMailSenderImpl' is defined
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'javaMailSenderImpl' is defined
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:360)
    	...
    Plus haut dans les logs je me suis aperçu que appContext-mail ne semblait pas pris en compte:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    09:47:33,093 INFO  [ContextLoader] Root WebApplicationContext: initialization started
    09:47:33,093 INFO  [[/opalys-server-remoting]] Loading Spring root WebApplicationContext
    09:47:33,180 INFO  [CollectionFactory] JDK 1.4+ collections available
    09:47:33,195 INFO  [CollectionFactory] Commons Collections 3.x available
    09:47:33,230 INFO  [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
    09:47:33,792 INFO  [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext-dataSource.xml]
    09:47:33,851 INFO  [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext-quartz.xml]
    09:47:33,868 INFO  [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext-server-authentication.xml]
    09:47:33,962 INFO  [XmlWebApplicationContext] Bean factory for application context [Root WebApplicationContext]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [messageSource,sessionFactory,hibernateInterceptor,pointDao,particularPointDao,axisDao,referenceDao,passagePointDao,varianteDao,userDao,roleDao,regularityFormDao,endOfMissionMessageDao,effectiveTrancheDao,trainSetDao,effectivePassageDao,incidentFormDao,eventTargetDao,eventDao,actionDao,eventTargetTypeDao,eventTypeDao,actionTypeDao,emailActionTypeDao,emailUserActionTypeDao,emailMailingListActionTypeDao,mailingListDao,stateDao,breakageFormDao,incidentDao,incidentTypeDao,effectDao,effectivePassageIssueDao,varianteSpecialCaseDao,trancheDao,breakageDao,incidentLocationDao,incidentFormNoticeSenderDao,administrationService,dataImportService,echoService,securityService,trafficGeneratorService,schedulerService,valentysService,incidentService,breakageService,regularityService,passengerFileParsingService,serviceSecurityInterceptor,serviceAccessDecisionManager,serviceDecisionVoter,dataSource,transactionManager,scheduler,basicProcessingFilter,authenticationEntryPoint,opalysAuthenticationManager,daoAuthenticationProvider,userCacheManager,userCacheBackend,userAuthenticationCache,passwordEncoder,opalysUserDetailsService]; root of BeanFactory hierarchy
    09:47:33,983 INFO  [XmlWebApplicationContext] 64 beans defined in application context [Root WebApplicationContext]
    Je pense que le pb vient de là, mais pourquoi? Quelqu'un peut-il m'expliquer?
    Nicolas.

  2. #2
    Rédacteur
    Avatar de Hikage
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    1 177
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2004
    Messages : 1 177
    Par défaut
    Effectivement, c'est assez bizarre.

    Vérifie dans le .war généré par Maven l'existence du fichier applicationContext-mail.xml, ainsi que la ligne correspondante dans ton beanRefFactory.xml.

    Et essaye de vider les fichiers temporaire de JBoss, au cas ou
    Hikage
    SCJP / SCWCD & SCWSJD Certified / Spring Framework Certified
    [Personal Web] [CV]

    F.A.Q Spring Framework - Participez !

  3. #3
    Membre confirmé
    Inscrit en
    Mars 2007
    Messages
    179
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 179
    Par défaut
    Bon en fait j'ai une archi un peu particulière, j'ai un module Web mais pour l'instant je ne l'utilise pas. Cependant, pour mettre en place l'utilisation via Spring de JavaMail, j'ai lu qu'il fallait configurer un DispatchServlet, dans le cadre du spring-remoting.

    Donc, j'ai regardé. Dans mon jar de mon module business, app-mail est bien généré.
    Mais dans le war de mon module web (là où donc il y aurait le DispatchServlet utilisé par spring-remoting), le applicationContext-mail n'apparaît pas.

    Dans le web.xml du war, j'ai:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
     
    <web-app>
     
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/applicationContext.xml
                /WEB-INF/applicationContext-dataSource.xml
                /WEB-INF/applicationContext-quartz.xml
                /WEB-INF/applicationContext-server-authentication.xml
            </param-value>
        </context-param>
     
        <filter>
            <filter-name>opalys-richclient_HTTP_BASIC_Authorization_Filter</filter-name>
            <filter-class>org.acegisecurity.util.FilterToBeanProxy</filter-class>
            <init-param>
                <param-name>targetClass</param-name>
                <param-value>org.acegisecurity.ui.basicauth.BasicProcessingFilter</param-value>
             </init-param>
        </filter>
     
        <filter-mapping>
            <filter-name>opalys-richclient_HTTP_BASIC_Authorization_Filter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
     
        <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
     
        <servlet>
            <servlet-name>opalys-remoting</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>
                    /WEB-INF/applicationContext-export-remoteServices.xml
                </param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
     
        <servlet-mapping>
            <servlet-name>opalys-remoting</servlet-name>
            <url-pattern>/*</url-pattern>
        </servlet-mapping>
     
    </web-app>
    Et comme on est dans le module Web, y a pas de beanRefFactory.

    Désolé, c'est un peu fouilli tout çà. Je débute et j'utilise AndroMDA pour générer les fichiers de config Spring notamment (donc les beans également). Du coup, une couche d'abstraction a été rajoutée et quand je dois descendre (ici pour rajouter la gestion des mails), je rencontre quelques problèmes.
    J'ai pas tout compris de l'histoire de spring-remoting qui a besoi d'un DispatchServlet, c'est un peu bizarre, mais en tout cas c'est ce que j'ai trouvé sur un forum et çà semblait marcher. Je crois que c'est parce que pour spring-remoting on passe par du HTTP et donc on a besoin d'un servlet (voir ici)

    Je n'ai donc pas le app-mail.xml. Et dans ma servlet opalys-remoting, il n'est fait aucune référence à app-mail.xml. Peut-être est-ce là que je dois rajouter une référence?
    En tout cas dans /WEB-INF/applicationContext-export-remoteServices.xml, j'ai bien la référence du bean javaMailSender, sensé référencer le bean défini dans app-mail:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
        <!-- JavaMailSender Remote Service exporter  -->
        <bean name="/JavaMailSender" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
            <property name="service"><ref bean="javaMailSender"/></property>
            <property name="serviceInterface"><value>org.springframework.mail.javamail.JavaMailSender</value></property>
        </bean>
     
        <!-- ==================== End of REMOTE SERVICE DEFINITIONS ======================= -->
     
        <!-- Authentication service for remote rich clients -->
        <bean name="/RemoteAuthenticationManagerService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
            <property name="service">
                <bean class="org.acegisecurity.providers.rcp.RemoteAuthenticationManagerImpl">
                    <property name="authenticationManager">
                        <ref bean="opalysAuthenticationManager"/>
                    </property>
                </bean>
            </property>
            <property name="serviceInterface">
                <value>org.acegisecurity.providers.rcp.RemoteAuthenticationManager</value>
            </property>
        </bean>

  4. #4
    Rédacteur
    Avatar de Hikage
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    1 177
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2004
    Messages : 1 177
    Par défaut
    Désolé du retard, j'ai plus eu trop le temps de regarder à ton problème malheureusement.

    Je vais essaye de trouver du temps ce weekend, je te tiens au courant
    Hikage
    SCJP / SCWCD & SCWSJD Certified / Spring Framework Certified
    [Personal Web] [CV]

    F.A.Q Spring Framework - Participez !

  5. #5
    Membre confirmé
    Inscrit en
    Mars 2007
    Messages
    179
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 179
    Par défaut
    Hey Hikage, as tu eu le temps de réfléchir à mon problème? Car là je suis à nouveau devant ma machine et le pb se pose à nouveua

  6. #6
    Rédacteur
    Avatar de Hikage
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    1 177
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2004
    Messages : 1 177
    Par défaut
    Et si tu ajoute

    WEB-INF/applicationContext-mail.xml

    dans le

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/applicationContext.xml
                /WEB-INF/applicationContext-dataSource.xml
                /WEB-INF/applicationContext-quartz.xml
                /WEB-INF/applicationContext-server-authentication.xml
            </param-value>
        </context-param>
    Hikage
    SCJP / SCWCD & SCWSJD Certified / Spring Framework Certified
    [Personal Web] [CV]

    F.A.Q Spring Framework - Participez !

Discussions similaires

  1. Envoi de mail au format html
    Par Mephyston dans le forum C++Builder
    Réponses: 2
    Dernier message: 22/01/2004, 12h29
  2. Envoi de mail au format Rich-Text
    Par LineLe dans le forum ASP
    Réponses: 4
    Dernier message: 29/10/2003, 16h27
  3. envoi de mail avec attachement de fichier
    Par GMI3 dans le forum Modules
    Réponses: 2
    Dernier message: 24/09/2003, 11h22
  4. Outlook ne se ferme pas après un envoi de mail
    Par Joke dans le forum VBA Access
    Réponses: 2
    Dernier message: 07/06/2003, 17h32
  5. envoi de mail, protocol SMTP langage C
    Par Heimdall dans le forum Développement
    Réponses: 2
    Dernier message: 23/05/2003, 11h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo