I'm using Spring,Quartz to schedule send email function.But I can't do that
This is my error
java.lang.NullPointerException
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTr ansport.java:557)
at org.springframework.mail.javamail.JavaMailSenderIm pl.doSend(JavaMailSenderImpl.java:382)
at org.springframework.mail.javamail.JavaMailSenderIm pl.send(JavaMailSenderImpl.java:291)
at org.springframework.mail.javamail.JavaMailSenderIm pl.send(JavaMailSenderImpl.java:277)
at org.vnitt.service.SendMailService.sendMail(SendMai lService.java:59)
at org.vnitt.shedule.SendMailJob.executeInternal(Send MailJob.java:47)
at org.springframework.scheduling.quartz.QuartzJobBea n.execute(QuartzJobBean.java:90)
at org.quartz.core.JobRunShell.run(JobRunShell.java:2 02)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run (SimpleThreadPool.java:525)
---And here is my config file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailS enderImpl">
<property name="defaultEncoding" value="UTF-8"/>
<property name="host" value="smtp.gmail.com" />
<property name="port" value="465" />
<property name="protocol" value="smtps" />
<property name="username" value="myemail#gmail.com"/>
<property name="password" value="mypass"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtps.auth">true</prop>
<prop key="mail.smtps.starttls.enable">true</prop>
<prop key="mail.smtps.debug">true</prop>
</props>
</property>
</bean>
<bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage" >
<property name="from" value="myemail#gmail.com" />
<property name="subject" value="Testing send email using Spring and Gmail " />
</bean>
<bean class="org.springframework.scheduling.quartz.Sched ulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronSendMailTrigger"/>
</list>
</property>
</bean>
<!-- end config Quartz to schdule a task -->
<!-- begin config to schedule SendMailService -->
<bean id="sendMailService"
class="org.service.SendMailService">
<property name="mailSender">
<ref bean="mailSender"/>
</property>
<property name="mailMessage">
<ref bean="mailMessage"/>
</property>
</bean>
<!-- config JobDetail -->
<bean id="sendMailJob"
class="org.springframework.scheduling.quartz.JobDe tailBean">
<property name="jobClass">
<value>org.shedule.SendMailJob</value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="sendMailService">
<ref bean="sendMailService"/>
</entry>
</map>
</property>
</bean>
<!-- config cron trigger -->
<bean id="cronSendMailTrigger"
class="org.springframework.scheduling.quartz.CronT riggerBean">
<property name="jobDetail">
<ref bean="sendMailJob"/>
</property>
<property name="cronExpression">
<value>0 0/1 * * * ?</value>
</property>
</bean>
<!-- end config to schedule SendMailService -->
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/spring_quartz_scheduler.vnitt">mainController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlVi ew</value>
</property>
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
Plz help me to solve this problem!
Thanks
EDIT
Thanks for your answer. I have fix my bug, I did not set recipient in my code and my configuration.That's cause.
Are you specifying recipients for your email message? You're not doing so in Spring context (to is not set). That's most likely the reason for NPE.
I am also faced the similar kind of issue and its due to no recipients.
Related
I am new to spring mvc framework. Here I am getting GC overhead limit exceeded exception when I deploy war file of my application by starting Apache Tomcat 7 service.
bean.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true">
<bean id="loadproperties" class="com.dyulok.dewa.utility.ProjectProperties">
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>file:${CATALINA_HOME}/conf/dyulokeventwebapplication_project.properties
</value>
</property>
</bean>
<bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>${jdbc.mysql.url}</value>
</property>
<property name="username">
<value>${jdbc.mysql.username}</value>
</property>
<property name="password">
<value>${jdbc.mysql.password}</value>
</property>
<property name="validationQuery">
<value>SELECT 1</value>
</property>
<property name="testOnBorrow">
<value>true</value>
</property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg>
<ref bean="dataSource" />
</constructor-arg>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache.use_structured_entries">false</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.query.factory_class"></prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value> com.dyulok.dewa.model.event.Event</value>
<value>com.dyulok.dewa.model.event.ConferenceEvent</value>
<value>com.dyulok.dewa.model.organizer.EventOrganizer</value>
<value>com.dyulok.dewa.model.inbox.Inbox</value>
<value>com.dyulok.dewa.model.inbox.Message</value>
<value>com.dyulok.dewa.model.schedule.SubEvent</value>
<value>com.dyulok.dewa.model.schedule.ConferenceSession</value>
<value>com.dyulok.dewa.model.speakers.Speaker</value>
<value>com.dyulok.dewa.model.venue.Venue</value>
<value>com.dyulok.dewa.model.venue.SubVenue</value>
<value>com.dyulok.dewa.model.exhibitors.Exhibitor</value>
<value>com.dyulok.dewa.model.exhibitors.ExhibitorCollection</value>
<value>com.dyulok.dewa.model.feedback.FeedBack</value>
<value>com.dyulok.dewa.model.feedback.EventFeedback</value>
<value>com.dyulok.dewa.model.feedback.SubEventFeedback</value>
<value>com.dyulok.dewa.model.schedule.SubEventResource</value>
<value>com.dyulok.dewa.model.image.Image</value>
<value>com.dyulok.dewa.model.register.RegistrationMetadata</value>
<value>com.dyulok.dewa.model.register.RegistrationData</value>
<value>com.dyulok.dewa.model.speakers.CallForSpeaker</value>
<value>com.dyulok.dewa.model.displayoptions.ConferenceTabDisplayOptions
</value>
<value>com.dyulok.dewa.model.user.User</value>
<value>com.dyulok.dewa.model.user.UserFriends</value>
<value>com.dyulok.dewa.model.organizer.EventOrganizerAccountDetails
</value>
<value>com.dyulok.dewa.model.ticket.TicketDetails</value>
<value>com.dyulok.dewa.model.ticket.TicketDiscount</value>
<value>com.dyulok.dewa.model.ticket.TransactionalDetail</value>
<value>com.dyulok.dewa.model.payouts.PayoutsTransaction</value>
</list>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="annotatedPackages">
<list>
<value>com.dyulok.dewa</value>
</list>
</property>
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="EventDataDaoImpl" class="com.dyulok.dewa.dao.event.EventDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="EventDataServiceImpl" class="com.dyulok.dewa.service.event.EventDataServiceImpl">
<property name="eventdatadao">
<ref local="EventDataDaoImpl" />
</property>
<property name="subEventDataService">
<ref local="SubEventDataServiceImpl" />
</property>
<property name="inboxDataService">
<ref local="InboxDataServiceImpl" />
</property>
<property name="exhibitorDataService">
<ref local="ExhibitorDataServiceImpl" />
</property>
<property name="feedbackDataService">
<ref local="FeedbackDataServiceImpl" />
</property>
<property name="speakerDataService">
<ref local="SpeakerDataServiceImpl" />
</property>
<property name="imageDataService">
<ref local="ImageDataServiceImpl" />
</property>
<property name="organizerDataService">
<ref local="EventOrganizerDataServiceImpl" />
</property>
<property name="callForSpeakerDataService">
<ref local="CallForSpeakerDataServiceImpl" />
</property>
<property name="registrationMetadataDataService">
<ref local="RegistrationMetadataDataServiceImpl" />
</property>
<property name="registrationDataService">
<ref local="RegistrationDataServiceImpl" />
</property>
<property name="conferenceTabDisplayOptionsDataService">
<ref local="ConferenceTabDisplayOptionsDataServiceImpl" />
</property>
<property name="ticketDetailsDataService">
<ref local="TicketDetailsDataServiceImpl" />
</property>
</bean>
<bean id="ExhibitorDataDaoImpl" class="com.dyulok.dewa.dao.exhibitor.ExhibitorDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="ExhibitorDataServiceImpl"
class="com.dyulok.dewa.service.exhibitor.ExhibitorDataServiceImpl">
<property name="exhibitordatadao">
<ref local="ExhibitorDataDaoImpl" />
</property>
</bean>
<bean id="FeedbackDataDaoImpl" class="com.dyulok.dewa.dao.feedback.FeedbackDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="FeedbackDataServiceImpl"
class="com.dyulok.dewa.service.feedback.FeedbackDataServiceImpl">
<property name="feedbackdatadao">
<ref local="FeedbackDataDaoImpl" />
</property>
</bean>
<bean id="InboxDataDaoImpl" class="com.dyulok.dewa.dao.inbox.InboxDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="InboxDataServiceImpl" class="com.dyulok.dewa.service.inbox.InboxDataServiceImpl">
<property name="inboxdatadao">
<ref local="InboxDataDaoImpl" />
</property>
</bean>
<bean id="EventOrganizerDataDaoImpl" class="com.dyulok.dewa.dao.organizer.EventOrganizerDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="EventOrganizerDataServiceImpl"
class="com.dyulok.dewa.service.organizer.EventOrganizerDataServiceImpl">
<property name="organizerdatadao">
<ref local="EventOrganizerDataDaoImpl" />
</property>
<property name="eventdataservice">
<ref local="EventDataServiceImpl" />
</property>
<property name="organizeraccountdataservice">
<ref local="EventOrganizerAccountDataServiceImpl"/>
</property>
</bean>
<bean id="EventOrganizerAccountDataDaoImpl"
class="com.dyulok.dewa.dao.organizer.EventOrganizerAccountDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="EventOrganizerAccountDataServiceImpl"
class="com.dyulok.dewa.service.organizer.EventOrganizerAccountDataServiceImpl">
<property name="organizeraccountdatadao">
<ref local="EventOrganizerAccountDataDaoImpl" />
</property>
</bean>
<bean id="SubEventDataDaoImpl" class="com.dyulok.dewa.dao.schedule.SubEventDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
<property name="jdbcTemplate">
<ref local="jdbcTemplate" />
</property>
</bean>
<bean id="SubEventDataServiceImpl"
class="com.dyulok.dewa.service.schedule.SubEventDataServiceImpl">
<property name="subeventdatadao">
<ref local="SubEventDataDaoImpl" />
</property>
</bean>
<bean id="SpeakerDataDaoImpl" class="com.dyulok.dewa.dao.speaker.SpeakerDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
<property name="jdbcTemplate">
<ref local="jdbcTemplate" />
</property>
</bean>
<bean id="SpeakerDataServiceImpl" class="com.dyulok.dewa.service.speaker.SpeakerDataServiceImpl">
<property name="speakerdatadao">
<ref local="SpeakerDataDaoImpl" />
</property>
<property name="subEventDataService">
<ref local="SubEventDataServiceImpl" />
</property>
<property name="imageDataService">
<ref local="ImageDataServiceImpl" />
</property>
</bean>
<bean id="ImageDataDaoImpl" class="com.dyulok.dewa.dao.image.ImageDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="ImageDataServiceImpl" class="com.dyulok.dewa.service.image.ImageDataServiceImpl">
<property name="imagedatadao">
<ref local="ImageDataDaoImpl" />
</property>
</bean>
<bean id="RegistrationMetadataDataDaoImpl"
class="com.dyulok.dewa.dao.register.RegistrationMetadataDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="RegistrationMetadataDataServiceImpl"
class="com.dyulok.dewa.service.register.RegistrationMetadataDataServiceImpl">
<property name="registrationMetadataDataDao">
<ref local="RegistrationMetadataDataDaoImpl" />
</property>
</bean>
<bean id="RegistrationDataDaoImpl" class="com.dyulok.dewa.dao.register.RegistrationDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="RegistrationDataServiceImpl"
class="com.dyulok.dewa.service.register.RegistrationDataServiceImpl">
<property name="registrationdatadao">
<ref local="RegistrationDataDaoImpl" />
</property>
</bean>
<bean id="TicketDetailsDataDaoImpl" class="com.dyulok.dewa.dao.ticket.TicketDetailsDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="TicketDetailsDataServiceImpl"
class="com.dyulok.dewa.service.ticket.TicketDetailsDataServiceImpl">
<property name="ticketdetailsdatadao">
<ref local="TicketDetailsDataDaoImpl" />
</property>
<property name="ticketdiscountdataservice">
<ref local="TicketDiscountDataServiceImpl" />
</property>
</bean>
<bean id="TicketDiscountDataDaoImpl" class="com.dyulok.dewa.dao.ticket.TicketDiscountDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="TicketDiscountDataServiceImpl"
class="com.dyulok.dewa.service.ticket.TicketDiscountDataServiceImpl">
<property name="ticketdiscountdatadao">
<ref local="TicketDiscountDataDaoImpl" />
</property>
</bean>
<bean id="TransactionDetailsDataDaoImpl"
class="com.dyulok.dewa.dao.ticket.TransactionDetailsDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="TransactionalDetailDataServiceImpl"
class="com.dyulok.dewa.service.ticket.TransactionalDetailDataServiceImpl">
<property name="transactionaldetaildatadao">
<ref local="TransactionDetailsDataDaoImpl" />
</property>
<property name="registrationDataService">
<ref local="RegistrationDataServiceImpl" />
</property>
<property name="eventOrganizerDataService">
<ref local="EventOrganizerDataServiceImpl" />
</property>
<property name="userDataService">
<ref local="UserDataServiceImpl" />
</property>
</bean>
<bean id="PayoutsTransactionDataDaoImpl"
class="com.dyulok.dewa.dao.payouts.PayoutsTransactionDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="PayoutsTransactionDataServiceImpl"
class="com.dyulok.dewa.service.payouts.PayoutsTransactionDataServiceImpl">
<property name="payoutsTransactionDataDao">
<ref local="PayoutsTransactionDataDaoImpl" />
</property>
</bean>
<bean id="CallForSpeakerDataDaoImpl" class="com.dyulok.dewa.dao.speaker.CallForSpeakerDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="CallForSpeakerDataServiceImpl"
class="com.dyulok.dewa.service.speaker.CallForSpeakerDataServiceImpl">
<property name="callForSpeakerDataDao">
<ref local="CallForSpeakerDataDaoImpl" />
</property>
</bean>
<bean id="ConferenceTabDisplayOptionsDataDaoImpl"
class="com.dyulok.dewa.dao.displayoptions.ConferenceTabDisplayOptionsDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="ConferenceTabDisplayOptionsDataServiceImpl"
class="com.dyulok.dewa.service.displayoptions.ConferenceTabDisplayOptionsDataServiceImpl">
<property name="displayoptionsdatadao">
<ref local="ConferenceTabDisplayOptionsDataDaoImpl" />
</property>
</bean>
<bean id="VenueDataDaoImpl" class="com.dyulok.dewa.dao.venue.VenueDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="VenueDataServiceImpl" class="com.dyulok.dewa.service.venue.VenueDataServiceImpl">
<property name="venuedatadao">
<ref local="VenueDataDaoImpl" />
</property>
<property name="eventdataservice">
<ref local="EventDataServiceImpl" />
</property>
</bean>
<bean id="UserDataDaoImpl" class="com.dyulok.dewa.dao.user.UserDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
<property name="jdbcTemplate">
<ref local="jdbcTemplate" />
</property>
</bean>
<bean id="UserDataServiceImpl" class="com.dyulok.dewa.service.user.UserDataServiceImpl">
<property name="userDataDao">
<ref local="UserDataDaoImpl" />
</property>
<property name="registrationDataService">
<ref local="RegistrationDataServiceImpl" />
</property>
<property name="accountDataService">
<ref local="EventOrganizerAccountDataServiceImpl"/>
</property>
</bean>
<bean id="UserFriendsDataDaoImpl" class="com.dyulok.dewa.dao.user.UserFriendsDataDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="UserFriendsDataServiceImpl" class="com.dyulok.dewa.service.user.UserFriendsDataServiceImpl">
<property name="userFriendsDataDao">
<ref local="UserFriendsDataDaoImpl" />
</property>
</bean>
<bean id="SystemDataServiceImpl" class="com.dyulok.dewa.service.system.SystemDataServiceImpl" >
<property name="eventDataService">
<ref local="EventDataServiceImpl"/>
</property>
<property name="userDataService">
<ref local="UserDataServiceImpl"/>
</property>
<property name="organizerDataService">
<ref local="EventOrganizerDataServiceImpl"/>
</property>
</bean>
<bean id="event_data_hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"
lazy-init="true">
<constructor-arg>
<ref bean="sessionFactory" />
</constructor-arg>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<tx:annotation-driven proxy-target-class="true" />
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
</beans>
but when I simply run the command catalina run, command prompt shows following trace. Application runs successfully without any error.
Catalina log when run by command
Looks like my file is too big. So I have posted Catalina log command.
Catalina log when run by service
It contains error. Catalina log service
I found lot of people saying increase the jvm size. I would have done that, but the question is why does application run by command line and does not run by starting tomcat7 service.
Update: Increasing jvm heap size to 2 GB did not solve my problem. Please help.
When starting Tomcat from the command line it will use the JAVA_HOME and the Path variable to locate the JRE to start the JVM.
The service version AUTO mode will find the JVM from the Windows registry.
Check your window registry to see which JVM does the service version actually uses. Maybe you have more than one JDKs installed on your system.
Is there a way to configure and setup Embedded Tomcat in Spring? I can do so easily with Jetty 7 that I created a standalone Java application that will start Jetty as webcontainer and finally JUnit test can call the BO via HTTPInvoker.
To me, it seems I have to write code to do so by using Tomcat?
Spring xml file
<!-- Manually start server after setting parent context. (init-method="start") -->
<bean id="jettyServer"
class="org.eclipse.jetty.server.Server"
init-method="start"
destroy-method="stop">
<property name="threadPool">
<bean id="ThreadPool"
class="org.eclipse.jetty.util.thread.ExecutorThreadPool">
<constructor-arg value="0" />
<!--property name="corePoolSize" value="${jetty.server.thread.pool.core.pool.size}"/>
<property name="maximumPoolSize" value="${jetty.server.thread.pool.max.pool.size}"/-->
</bean>
</property>
<property name="connectors">
<list>
<bean id="Connector"
class="org.eclipse.jetty.server.nio.SelectChannelConnector"
p:port="${jetty.server.port}"
p:maxIdleTime="${jetty.server.max.idle.time}"
p:acceptors="${jetty.server.acceptor.num}"
p:confidentialPort="${jetty.server.ssl.port}" />
</list>
</property>
<property name="handler">
<bean class="org.eclipse.jetty.server.handler.HandlerCollection">
<property name="handlers">
<list>
<bean class="org.eclipse.jetty.servlet.ServletContextHandler">
<property name="contextPath" value="/"/>
<property name="sessionHandler">
<bean class="org.eclipse.jetty.server.session.SessionHandler"/>
</property>
<property name="resourceBase" value="."/>
<property name="servletHandler">
<bean class="org.eclipse.jetty.servlet.ServletHandler">
<property name="servlets"> <!-- servlet definition -->
<list>
<!-- default servlet -->
<bean class="org.eclipse.jetty.servlet.ServletHolder">
<property name="name" value="DefaultServlet"/>
<property name="servlet">
<bean class="org.springframework.web.servlet.DispatcherServlet"/>
</property>
<property name="initParameters">
<map>
<entry key="contextConfigLocation" value="classpath:config/DefaultServlet-servlet.xml" />
</map>
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list><!-- servlet mapping -->
<bean class="org.eclipse.jetty.servlet.ServletMapping">
<property name="pathSpecs">
<list><value>/</value></list>
</property>
<property name="servletName" value="DefaultServlet"/>
</bean>
</list>
</property>
</bean>
</property>
</bean>
<bean class="org.eclipse.jetty.server.handler.RequestLogHandler">
<property name="requestLog">
<bean class="org.eclipse.jetty.server.NCSARequestLog">
<constructor-arg value="${jetty.server.log.dir}/jetty-yyyy_mm_dd.log"/>
<property name="extended" value="false"/>
</bean>
</property>
</bean>
</list>
</property>
</bean>
</property>
</bean>
DefaultServlet-servlet.xml
<!-- This default handler takes care of each of the services enumerated below -->
<bean id="defaultHandlerMapping"
class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<bean id="helloService" class="com.company.ws.bo.HelloServiceImpl"/>
<!-- SpringHTTP Service Exposure -->
<bean name="/HelloService"
class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"
lazy-init="true">
<property name="service" ref="helloService" />
<property name="serviceInterface"
value="com.company.ws.bo.IHelloService" />
</bean>
Tomcat 7 can be used as an embedded Server. As far as I know there is no special spring support, but you don't need special spring support to start an tomcat out of an spring application.
#See:
this blog and this (german)
I developed a login mechanism for one of my projects with Spring 2.5 , asegi security 1.0.7 and I used Tomcat 6 as my development server.When I was developing the project everything worked fine and I could successfully log-in.The problem begun when I deployed my application on the production server.From the moment I deployed the application on the production tomcat 6 I could not log-in even with the correct username and password and the most weird of all is that no exception is thrown.I just can't log -in!
here is the application-context.xml of the application:
<bean id="authedicationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="userDetailService"/>
</bean>
<bean id="authenticationEntryPoint" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
<property name="loginFormUrl" value="/login.htm" />
</bean>
<bean id="filterChainProxy"
class="org.acegisecurity.util.FilterChainProxy">
<property name="filterInvocationDefinitionSource">
<value>
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/**=authenticationProcessingFilter,exceptionTranslationFilter
</value>
</property>
</bean>
<bean id="authenticationProcessingFilter"
class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
<property name="authenticationManager" ref="authenticationManager"/>
<property name="authenticationFailureUrl" value="/error.htm" />
<property name="defaultTargetUrl" value="/admin_menu.htm" />
<property name="filterProcessesUrl" value="/j_acegi_security_check" />
</bean>
<bean id="roleVoter" class="org.acegisecurity.vote.RoleVoter"/>
<bean id="accessDecisionManager" class="org.acegisecurity.vote.UnanimousBased">
<property name="decisionVoters">
<list>
<ref bean="roleVoter"/>
</list>
</property>
<property name="allowIfAllAbstainDecisions" value="true"/>
</bean>
<bean id="filterSecurityInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
<property name="authenticationManager" ref="authenticationManager"/>
<property name="accessDecisionManager" ref="accessDecisionManager"/>
<property name="objectDefinitionSource">
<value>
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/add_article.htm=ROLE_ADMIN
/add_publication.htm=ROLE_ADMIN
/admin_menu.htm=ROLE_ADMIN
</value>
</bean>
</property>
</bean>
<bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager">
<property name="providers">
<list>
<ref bean="authedicationProvider"/>
</list>
</property>
</bean>
<bean id="userDetailService" class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl">
<property name="dataSource" ref="datasource"/>
<property name="usersByUsernameQuery">
<value>
SELECT username,password,'true' AS enabled FROM Users where username=?
</value>
</property>
<property name="authoritiesByUsernameQuery">
<value>
SELECT username,role_name FROM Roles r,Users u WHERE r.user=u.id AND u.username=?
</value>
</property>
</bean>
Am I missing somthing?Any help would be really appreciated!Thank you in advance
Is this what you have <bean id="authe**d**icationProvider" in your first line of application file ?
I'm trying to create a webserver embedding jetty (rather than Java EE) , and map my servlets RESTfully, using jersey.
I'm using spring for dependency injection, and mapping the servlets as beans
However, when I try to make an HTTP req to the mapped servlets, i get error 500- server error, or 404, page not found.
I'm not sure if i'm doing this the right way, and I should probably be using the jetty.xml rather than this. (wondering if there's a shorcut using jetty.xml)
<bean id="contexts"
class="org.eclipse.jetty.server.handler.ContextHandlerCollection">
</bean>
<bean id="server" class="org.mortbay.jetty.spring.Server"
init-method="start" destroy-method="stop">
<property name="threadPool">
<bean id="ThreadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<property name="minThreads" value="10" />
<property name="maxThreads" value="50" />
</bean>
</property>
<property name="connectors">
<list>
<bean id="Connector" class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<property name="port" value="8080" />
</bean>
</list>
</property>
<property name="handler">
<bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<property name="handlers">
<list>
<ref bean="contexts" />
<bean class="org.eclipse.jetty.server.handler.ResourceHandler">
<property name="directoriesListed" value="true" />
<property name="welcomeFiles">
<list>
<value>index.jsp</value>
</list>
</property>
<property name="resourceBase" value="./WebContent" />
</bean>
<bean id="myServletHandler" class="org.eclipse.jetty.servlet.ServletHandler">
<property name="servlets">
<list>
<bean id="jerseyServletContainer" class="org.eclipse.jetty.servlet.ServletHolder">
<property name="name" value="jersey" />
<property name="servlet">
<bean class="com.sun.jersey.spi.container.servlet.ServletContainer" />
</property>
<property name="initParameters">
<map>
<entry key="com.sun.jersey.config.property.resourceConfigClass"
value="com.sun.jersey.api.core.PackagesResourceConfig" />
<entry key="com.sun.jersey.config.property.packages"
value="servlets" />
</map>
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list>
<bean id="jerseyMapping" class="org.eclipse.jetty.servlet.ServletMapping">
<property name="servletName" value="jersey" />
<property name="pathSpec" value="/*" />
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
</property>
<property name="beans">
<list>
<bean id="ContextDeployer" class="org.eclipse.jetty.deploy.ContextDeployer">
<property name="contexts" ref="contexts" />
<property name="directory" value="contexts" />
<property name="scanInterval" value="5" />
</bean>
</list>
</property>
</bean>
I have one class in the servlets package: DoNothing.java
package servlets;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
#Path("/nothing")
public class doNothing
{
#GET
#Produces("text/plain")
public String returnNothing()
{
return ("test");
}
}
what in the world am I doing wrong? or should I ask what in the world am I doing right?
Thanks
I was looking for a way to use Jersey+Spring+Embedded Jetty and found this question. I tried your method and it actually works.
If you want to actually use Spring beans in your resources you can use jersey-spring:
<bean id="server" class="org.mortbay.jetty.Server" destroy-method="stop">
<property name="connectors">
<list>
<bean id="Connector" class="org.mortbay.jetty.nio.SelectChannelConnector">
<property name="port" value="8080"/>
</bean>
</list>
</property>
<property name="handlers">
<list>
<bean class="org.mortbay.jetty.servlet.Context">
<property name="contextPath" value="/"/>
<property name="sessionHandler">
<bean class="org.mortbay.jetty.servlet.SessionHandler" />
</property>
<property name="servletHandler">
<bean class="org.mortbay.jetty.servlet.ServletHandler">
<property name="servlets">
<list>
<bean class="org.mortbay.jetty.servlet.ServletHolder">
<property name="name" value="jersey" />
<property name="servlet">
<bean class="com.sun.jersey.spi.spring.container.servlet.SpringServlet" />
</property>
<property name="initParameters">
<map>
<entry key="com.sun.jersey.spi.container.ContainerRequestFilters"
value="com.sun.jersey.api.container.filter.LoggingFilter" />
<entry key="com.sun.jersey.spi.container.ContainerResponseFilters"
value="com.sun.jersey.api.container.filter.LoggingFilter" />
</map>
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list>
<bean class="org.mortbay.jetty.servlet.ServletMapping">
<property name="servletName" value="jersey"/>
<property name="pathSpecs">
<list>
<value>/*</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
</property>
<property name="eventListeners">
<list>
<bean id="requestContextListener" class="org.springframework.web.context.request.RequestContextListener"/>
<bean id="contextLoaderListener" class="org.springframework.web.context.ContextLoaderListener"/>
</list>
</property>
<property name="initParams">
<map>
<entry key="contextConfigLocation" value="classpath:META-INF/AdditionalBeansContext.xml"/>
</map>
</property>
</bean><!--
--></list>
</property>
</bean>
In file AdditionalBeansContext.xml:
Then define your Resources with: #Component annotation, injected beans with #Autowired
I am implementing Quartz Job Store on Oracle DB using Spring Framework. My ApplicationContext.xml is below
<bean id="driverJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="BatchFileCollector" />
</bean>
<bean id="ranchTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="driverJob" />
<property name="startDelay" value="2000" />
<property name="repeatInterval" value="10000" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="ranchTrigger" />
</list>
</property>
<property name="dataSource">
<ref bean="dataSource.TEXAN"/>
</property>
<property name="applicationContextSchedulerContextKey">
<value>applicationContext</value>
</property>
<property name="autoStartup">
<value>true</value>
</property>
<property name="configLocation" value="classpath:quartz.properties"/>
</bean>
This configuration gives me the below error.
Caused by: org.quartz.JobPersistenceException:
Couldn't store trigger: The job (DEFAULT.driverJob) referenced by the trigger does not exist.
[See nested exception: org.quartz.JobPersistenceException: The job (DEFAULT.driverJob) referenced by the trigger does not exist.]
I am using Spring Framework 2.5.6. Do I have to upgrade my Quartz version?
I cannot find the problem.
Thanks for your help.
Your SchedulerFactoryBean needs to have the "driverJob" registered, too. Along with your triggers, add a list of jobDetails.
<bean id="job.statistics.DailyQPSValidationJobTrigger" class="org.quartz.CronTrigger">
<property name="name" value="DailyQPSValidationTrigger" />
<property name="jobName" value="DailyQPSValidation" />
<property name="jobGroup" value="Statistics" />
<property name="volatility" value="false" />
<!-- Each day, 4 o'clock AM -->
<property name="cronExpression" value="0 0 4 * * ?" />
</bean>
<!-- Scheduler -->
<bean id="job.SchedulerProperties" class="somecompany.someproduct.util.spring.PropertiesFactoryBean"
scope="singleton">
<property name="source">
<props>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.scheduler.instanceName">JobCluster</prop>
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.jobStore.useProperties">false</prop>
</props>
</property>
</bean>
<bean id="job.Scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" scope="singleton"
lazy-init="false">
<property name="startupDelay" value="30" />
<property name="waitForJobsToCompleteOnShutdown" value="true" />
<property name="dataSource" ref="jdbc.DataSource" />
<property name="quartzProperties" ref="job.SchedulerProperties" />
<property name="jobDetails">
<list>
<ref bean="job.statistics.DailyQPSValidationJobDetail" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="job.statistics.DailyQPSValidationJobTrigger" />
</list>
</property>
<property name="schedulerListeners">
<list>
<bean class="somecompany.someproduct.job.SchedulerErrorListener">
<property name="monitoringService" ref="monitoring.MonitoringService" />
</bean>
</list>
</property>
<property name="globalJobListeners">
<list>
<bean class="somecompany.someproduct.job.JobErrorListener">
<property name="name" value="JobErrorListener" />
<property name="monitoringService" ref="monitoring.MonitoringService" />
</bean>
</list>
</property>
</bean>
I have the same problem with Quartz 1.5.2 and Spring 3.0.4. The problem is that the JobStoreSupport class tries to store a cron trigger with a foreign key to the job (tries to load the job from the db), which is not persisted yet.
Same problem with quartz 1.6.1, 1.7.2 versions.
<bean id="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
depends-on="quartzDatabaseCreator">
<property name="autoStartup">
<value>true</value>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.jobStore.selectWithLockSQL">SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?
</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.${qrtz.delegateClass}
</prop>
</props>
</property>
<property name="triggers">
<list>
<ref bean="cronTrigger"/>
</list>
</property>
<property name="schedulerContextAsMap">
<map>
<entry key="sygnoServerHelper"><ref bean="sygnoServerHelper"/></entry>
<entry key="requestDAO"><ref bean="requestDAO"/></entry>
<entry key="alairoCache"><ref bean="alairoCache"/></entry>
</map>
</property>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="checkGracePeriodJob" />
<!-- # s m h dom mon dow [y] -->
<property name="cronExpression" value="0 0/5 * * * ?" />
</bean>
<bean id="checkGracePeriodJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.synergon.sygnoserver.CheckGracePeriodJob"/>
</bean>
I'm not sure if this will work, but you could try using:
<bean id="driverJob" .../>
instead of:
<bean name="driverJob" .../>