this is my XML configuration file in a maven project, I am trying to send an auto-generated message using a Hotmail id, sometimes it's working fine and sometimes I am getting an error sending mail
<bean id=" email" class=" org.springframework.mail.SimpleMailMessage"></bean>
<bean class="org.springframework.mail.javamail.JavaMailSenderImpl" id="mailSender">
<property value="smtp.live.com" name="host"/>
<property value="587" name="port"/>
<property value="xxxxxx#hotmail.com" name="username"/>
<property value="xxxxxxxxx" name="password"/>
<property name="javaMailProperties">
<props>
<prop key="mail.transport.protocol">smtp</prop>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.smtp.socketFactory.port">465</prop>
<prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
<prop key="mail.smtp.port">465</prop>
</props>
</property>
</bean>
after changing port name 587 to 25 it's working fine
Related
In our project's code, we are initialising slave DB Spring HibernateTransactionManager through xml as shown below:
<bean id="slaveSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">com.swiggy.delivery.deliveryboy.model.dao.CustomMySql5Dialect</prop>
<prop key="hibernate.show_sql">${hibernate.slave.showSql}</prop>
<prop key="hibernate.format_sql">${hibernate.slave.formatSql}</prop>
<prop key="hibernate.connection.url">${hibernate.slave.connection.url}</prop>
<prop key="hibernate.connection.driver_class">com.mysql.jdbc.ReplicationDriver</prop>
<prop key="hibernate.connection.username">${hibernate.slave.connection.username}</prop>
<prop key="hibernate.connection.password">${hibernate.slave.connection.password}</prop>
<prop key="hibernate.c3p0.min_size">${hibernate.slave.c3p0.min_size}</prop>
<prop key="hibernate.c3p0.max_size">${hibernate.slave.c3p0.max_size}</prop>
<prop key="hibernate.c3p0.timeout">300</prop>
<prop key="hibernate.c3p0.max_statements">0</prop>
<prop key="hibernate.c3p0.idle_test_period">3000</prop>
<prop key="hibernate.c3p0.max_idle_time_excess_connections">60</prop>
</props>
</property>
</bean>
<bean id="slaveTransactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="slaveSessionFactory" />
<property name="defaultTimeout" value="10" />
</bean>
Here, I want to understand that for DB read timeouts, which value would be used during the transaction, the hibernate.c3p0.timeoutvalue of 300 ms or the defaultTimeout value of 10 ms.
I tried to go through both Spring and Hibernate docs for this but could not get a clear answer on whether the defaultTImeout would override the hibernate.c3p0.timeout or not.
My hunch is that the timeout value picked would be 300 ms. But cannot confirm that.
I need a solution about tomcat datasource configuration.
I have 2 nginx front of my tomcats.These are feeding my app, these are Webservice.
Tomcat machines and database are in different ip blog so its going firewall in each request.
When i started my tomcats everythigs well.But for example after 10 hour our after 20 hour later everythings going bad.That tomcats can not set connection.All service down.I share my datasource file and hope you find some solution or some other suggestions other than datasource file.
http://www.springframework.org/schema/beans ----
http://www.springframework.org/schema/context/spring-context.xsd">
<property name="connectionProperties">
<props merge="default">
<prop key="v$session.program">ws_${server}</prop>
</props>
</property>
<property name="connectionCacheProperties">
<props merge="default">
<prop key="MinLimit">1</prop>
<prop key="MaxLimit">120</prop>
<prop key="InitialLimit">5</prop>
<prop key="MaxStatementsLimit">50</prop>
<prop key="ConnectionWaitTimeout">30</prop>
<prop key="InactivityTimeout">600</prop>
<prop key="AbandonedConnectionTimeout">180</prop>
<prop key="PropertyCheckInterval">300</prop>
<prop key="ValidateConnection">true</prop>
<prop key="TimeToLiveTimeout">600</prop>
</props>
</property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="nativeJdbcExtractor">
<bean class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor" />
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<bean class="com.ws.oracle.pool.JndiExporter">
<property name="bean" ref="dataSource" />
<property name="jndiName" value="dsName" />
</bean>
below is my quatz integration with Spring but it is not working i.e. Job is not getting triggered . I can see quartz is checking MySQL database in few MS so that means connection with MYSQL is fine and also records are getting inserted in tables but Sysout mentioned in below class is not coming in console. please advice what could be root cause -
from Spring config XML
<bean id="myTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5" />
<property name="maxPoolSize" value="50" />
<property name="WaitForTasksToCompleteOnShutdown" value="true" />
</bean>
<bean id="exampleBusinessObjectJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<bean name="exampleBusinessObjectJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="name" value="exampleBusinessObjectJob"/>
<property name="jobClass" value="com.aexp.mars.job.ExampleJob"/>
</bean>
</property>
<property name="cronExpression" value="0 */1 * * * ?"/>
</bean>
<bean id="exampleBusinessObjectJob" class="com.aexp.mars.job.ExampleJob">
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="applicationContextSchedulerContextKey" value="applicationContext"/>
<property name="autoStartup" value="true"/>
<property name="triggers">
<list>
<ref bean="exampleBusinessObjectJobTrigger" />
</list>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceName">MARS_SCHEDULER</prop>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.scheduler.instanceId">10000</prop>
<prop key="org.quartz.scheduler.instanceId">600000</prop>
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread">true</prop>
<prop key="org.quartz.threadPool.threadCount">3</prop>
<prop key="org.quartz.threadPool.threadPriority">5</prop>
<prop key="org.quartz.jobStore.misfireThreshold">60000</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.useProperties">false</prop>
<prop key="org.quartz.jobStore.dataSource">marsDS</prop>
<prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.jobStore.clusterCheckinInterval">15000</prop>
<prop key="org.quartz.jobStore.maxMisfiresToHandleAtATime">20</prop>
<prop key="org.quartz.dataSource.marsDS.driver">com.mysql.jdbc.Driver</prop>
<prop key="org.quartz.dataSource.marsDS.URL">{server_url}</prop>
<prop key="org.quartz.dataSource.marsDS.user">{user_name}</prop>
<prop key="org.quartz.dataSource.marsDS.password">{password}</prop>
<prop key="org.quartz.dataSource.marsDS.maxConnections">10</prop>
<prop key="org.quartz.dataSource.marsDS.validationQuery">select 1</prop>
<prop key="org.quartz.plugin.shutdownHook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop>
<prop key="org.quartz.plugin.shutdownHook.cleanShutdown">false</prop>
</props>
</property>
<property name="taskExecutor" ref="myTaskExecutor" />
<property name="jobFactory">
<bean class="com.aexp.mars.job.MarsSpringBeanJobFactory"/>
</property>
</bean>
**Java class - **
public class ExampleJob {
private static final Logger LOG = LoggerFactory.getLogger(ExampleJob.class);
protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
System.out.println("Job is running");
LOG.info("Job ran");
}
public void execute(JobExecutionContext ctx) throws JobExecutionException {
System.out.println("Job#1 is running");
LOG.info("Job ran");
}
}
Got the scenario . I changed the value of cron expression to run it in every 1 minute but it was still set to my previous value (i.e. early morning 3 AM) . i added below property and then new cron expression startd working ..
<property name="overwriteExistingJobs" value="true"/>
So here it goes..
I have configured two jndi in my glassfish server for communicating two different databases.And in my applicationContext.xml I have following configuration
<!-- Database connection 1 STARTS HERE-->
<jee:jndi-lookup id="JNDI1" jndi-name="jdbc/db1"/>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="JNDI1" />
<!-- <property name="annotatedClasses">
<list>
<value>com.test.db1.Person</value> //THIS WORKS FINE
</list>
</property>-->
<property name="packagesToScan" value="com.test.db1" /> //THIS IS STRANGE
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.connection.autocommit">false</prop>
</props>
</property>
</bean>
<!-- Database connection 1 ENDS HERE-->
<!-- Database connection 2 STARTS HERE-->
<jee:jndi-lookup id="JNDI2" jndi-name="jdbc/db2" />
<bean id="sessionFactory2"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="JNDI2" />
<property name="packagesToScan" value="com.test.db2" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.connection.autocommit">false</prop>
</props>
</property>
</bean>
<!-- Database connection 2 ENDS HERE-->
In package com.test.db1 I have only Person class and in com.test.db2 package I have two entities named Employee and Company.
The problem occurs when I use packageToScan property in both SessionFactory beans all 3 tables are created in both databases.And when I explicitly define entity classes using annotatedClasses property tables are generated in relevant databases as configured in jndi.I am not getting why this kind of results I am getting while using packageToScan.
I'll be grateful If someone can explain me in detail.
Thank you
may i know as my configuration is done directly on applicationContext.xml, i do not have persistence.xml . by default this is resource_loca or jta? do i need to add extra parameter if i want to use jta?
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<!-- xdb is defined by running the hsqldb as xdb (see above) -->
<property name="url">
<value>jdbc:oracle:thin:#theserver:1521:appsdb</value>
</property>
<property name="username">
<value>test</value>
</property>
<property name="password">
<value>test</value>
</property>
</bean>
<bean id="annotatedsessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="packagesToScan" value="com.company.x.model" >
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.max_size">20</prop>
<prop key="hibernate.c3p0.timeout">1800</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="hibernate.cache.provider_class">
com.company.x.services.ExternalEhCacheProvider
</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
RESOURCE_LOCAL only applies to JPA EntityManager, not to a Hibernate SessionFactory. Hibernate's Spring integration is rather smoother than it is with JPA, and so the only thing that determines the transactional behaviour is which transaction manager you use with it (either HibernateTransactionManager or JtaTransactionManager). It'll work with either one without you having to explicitly configure the SessionFactory.