Send Email using spring? - spring

Thanks in advance. I have to send mail using spring. When i tried the code it shows following Bean Exception in my console.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'mailSender' defined in class path resource [mail-simple.xml]:
Instantiation of bean failed;
nested exception is java.lang.ClassFormatError: Absent Code attribute in method that
is not native or abstract in class file javax/mail/MessagingException.
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that
is not native or abstract in class file javax/mail/MessagingException
Can anyone please help me to find this problem?

I've never seen anything like this, but the exception seems to be saying that it is trying to load a malformed class file for javax.mail.MessagingException. I suggest that you download a fresh copy of the JAR file that contains that class, etcetera.

Related

Unable to create retry-able datasource for spring boot jdbc

I would like to add the retry feature for database connection certain number of times until the app acquires it. For the I have used the spring-retry on the DataSource but it is not working. It is throwing the following error
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdbcTemplate' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfiguration.class]: Unsatisfied dependency expressed through method 'jdbcTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: ExistingValue must be an instance of com.zaxxer.hikari.HikariDataSource
I have seen the debug logs but those are not helpful. Here is the sample source code . kindly help
Note: the dependencies mentioned in build.gradle is required for my app. I have only extracted the retry part.
Your use-case is delaying the start of Spring Boot until your database is up. Spring actually ships with a component that does that. The DatabaseStartupValidator is that component and has existed since about Spring 1.x.
You can add it as a bean and it will wait for further bootstrapping until the database is up.
#Bean
public DatabaseStartupValidator databaseStartupValidator(DataSource dataSource) {
var dsv = new DatabaseStartupValidator();
dsv.setDataSource(dataSource);
return dsv;
}
For a more detailed explanation see this blog post of mine.

Error with Springboot 2.4.0 incompatible versions

I have followed the below link and have updated the dependent jar versions respectively for spring boot 2.4.0.
But I get the following error while starting the service:
o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException.
Message: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'newRelicMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfiguration.class]: Unsatisfied dependency expressed through method 'newRelicMeterRegistry' parameter 2;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newRelicClientProvider' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [io.micrometer.newrelic.NewRelicClientProvider]:
Factory method 'newRelicClientProvider' threw exception; nested exception is io.micrometer.core.instrument.config.validate.ValidationException: Multiple validation failures:
management.metrics.export.newrelic.apiKey was 'null' but it is required when publishing to Insights API
management.metrics.export.newrelic.accountId was 'null' but it is required when publishing to Insights API
So, I would like to understand where I will get compatible versions while upgrading to 2.4.0?
For example, I have updated these versions:
io.micrometer.micrometer-core // v1.6.2
io.micrometer.micrometer-registry-new-relic // v1.6.2
io.micrometer.micrometer-registry-prometheus // v1.6.2
spring.cloud.version // v2020.0.0-M6
org.springframework.cloud.spring-cloud-starter-sleuth // v2.2.5.RELEASE
redisson.version // v3.12.2
I am not familiar with the use of "io.micrometer.micrometer-registry-new-relic" api. But the problem looks like some validations are getting failed because of wrong value. Make sure your registry parameters are correct to get through the validations. Below is napshot of error from your error log.
nested exception is io.micrometer.core.instrument.config.validate.ValidationException: Multiple validation failures: management.metrics.export.newrelic.apiKey was 'null' but it is required when publishing to Insights API management.metrics.export.newrelic.accountId was 'null' but it is required when publishing to Insights API.
Also refer below link if that can help.
https://discuss.newrelic.com/t/error-with-micrometer-and-newrelic-with-springboot2/55988

SRVE0283E: Exception caught while initializing context: org.springframework.beans.factory.BeanCreationException

the project working fine on windows 7 , shows those Error when deploy the project on mac .
liberty server ,eclipse mars ,
strong text[ERROR ] SRVE0283E: Exception caught while initializing context: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMapppingContext': Invocation of init method failed; nested exception is javax.persistence.PersistenceException: java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "com.ibm.db2.jcc.am.Connection.prepareSQLJCall(Ljava/lang/String;ILcom/ibm/db2/jcc/SQLJSection;Lcom/ibm/db2/jcc/SQLJColumnMetaData;Lcom/ibm/db2/jcc/SQLJColumnMetaData;ZZIIIILjava/lang/String;[Ljava/lang/Object;)Lcom/ibm/db2/jcc/SQLJCallableStatement;" the class loader (instance of com/ibm/ws/classloading/internal/AppClassLoader) of the current class, com/ibm/db2/jcc/am/Connection, and the class loader (instance of sun/misc/Launcher$ExtClassLoader) for interface com/ibm/db2/jcc/SQLJConnection have different Class objects for the type c/SQLJSection;Lcom/ibm/db2/jcc/SQLJColumnMetaData;Lcom/ibm/db2/jcc/SQLJColumnMetaData;ZZIIIILjava/lang/String;[Ljava/lang/Object;)Lcom/ibm/db2/jcc/SQLJCallableStatement; used in the signature
at
Based on the existence of Launcher$ExtClassLoader in the error message, it looks like you've put a copy of the JDBC driver into your Java Extension Class Loader path (usually JAVA_HOME/jre/lib/ext). Because of that, the environment has visibility to classes from both that location and the application class loader, and that causes a duplicate visibility that leads to the LinkageError.
There are extremely rare cases that require the use of the Java Extension loader, but I don't believe JDBC drivers are typically among them, so simply removing it from jre/lib/ext is probably the most straightforward solution.

Need guidance on Introduction to Spring JMS Active MQ

I am following "I coding blog" which is very good for someone like me who wants to get into Spring, JMS and ActiveMQ.
When I run TestJMSListener as a java application, I am getting following error:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectionFactory' defined in class path resource [com/jms/helloworld/config/JMSConfig.xml]: Error setting property values;
nested exception is org.springframework.beans.NotWritablePropertyException:
Invalid property 'brokerurl' of bean class [org.apache.activemq.ActiveMQConnectionFactory]:
Bean property 'brokerurl' is not writable or has an invalid setter method.
Does the parameter type of the setter match the return type of the getter?
I do not know how to fix it, below is my JMSConfig.xml file:
your xml file here.
According to the documentation the property is called brokerURL, not brokerurl. Spring helpfully reported the cause of the problem in the exception message.

Spring Error : java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer

First 2 Parts Solved --- I still Got Another Error Below >>>>
I am having trouble w. this Struts - Spring - Hibernate Application.
I got the error while accessing the Action class on Struts. It failed during instantion of the ActionClass due to Spring failed to create a Hibernate object bean.
Then I used log4j to get the info. It complained about :
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [factory/bean.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [factory/bean.xml]: Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.hibernate.cfg.Configuration]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE
Here is the full log4j log on the console :pastebin/z6FFAUEE
Here is my bean.xml : pastebin.com/nREBZ99N
I am honestly not very sure what the error is about, because this is my first time using Spring Hibernate and also the AOP aspects.
I think I have all the libs needed, but I am not very sure too. I think it could be on the xml setting or some missing parameters.
Any helps / pointers is appreciated.
Thx
^^^^SOLVED -- Now I got another error
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V
this is probably another library issue : Google Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(Z)V
but i m not again vr sure since, I am new using this framework, I am not vr familiar / knowledgable.
Any help poiting out the error/cause would sincerely be appreciated.
There is a ton of libs jars and I am only familiar with few of them, mostly just guessing the others. The libs is inherited from other application. Any links on good reference on libs also appreciated.
Here they are : http://pastebin.com/tgz8UFfs
^^^^SOLVED - Solution : I removed the text files from lib.
I had this error now, complaining that: java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
It complains about error on creating serviceProxyTemplate .. etc cannot initiate ^ class
here is the full stack trace : http://pastebin.com/c7rqk5cR
What library is the error / what lib do I need ?
Thx for the help

Resources