How can i add spring mail api to my project - spring

I am getting below error. org.springframework.mail.javamail.JavaMailSenderImpl is already defined in lib folder. Is spring using javax.mail? Do I need to also add the javax.mail library to my lib folder?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailSender' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/mail/MessagingException
My bean;
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">

You have to download javax.mail.jar and add it to your classpath.

Related

Spring Migration to 5.3.19 from 4.3.29 issue with .binding files

I have started my migration of spring version from 4.3.29.RELEASE to 5.3.29 I have fixed some of the issues with servlet and AbstractClientHttpRequest files but I was facing some issue with .binding files, I see they were loading as part of application context after migrating the spring version to 5.3.19 , with the older version of Spring 4.3.29.RELEASE I was able to bring up my application with out any issues. Now with 5.3.19 when I start my application I am getting below issue.
03-May-2022 10:11:00.537 SEVERE [main] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TestMgmtDAO': Unsatisfied dependency expressed through field 'editorService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'editorService': Unsatisfied dependency expressed through field 'trentonMessagePublisher'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'trentonMessagePublisher' defined in class path resource [config/queue-config.xml]: Cannot resolve reference to bean 'jmsTemplate' while setting bean property 'jmsTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsTemplate' defined in class path resource [config/queue-config.xml]: Cannot resolve reference to bean 'connectionFactory' while setting bean property 'connectionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectionFactory' defined in class path resource [config/queue-config.xml]: Cannot resolve reference to bean 'testConnectionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testConnectionFactory' defined in class path resource [config/queue-config.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [TEST_QMGR_QCF] is not bound in this Context. Unable to find [TEST_QMGR_QCF].
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testConnectionFactory' defined in class path resource [config/queue-config.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [TEST_QMGR_QCF] is not bound in this Context. Unable to find [TEST_QMGR_QCF].
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myTestQueue' defined in class path resource [config/queue-config.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [Q_OUTBOUND_TEST.CHECK_TO_QUEUETON] is not bound in this Context. Unable to find [Q_OUTBOUND_TEST.CHECK_TO_QUEUETON].
My Sample .binding file is below , I am using IBM MQ.
TEST_QMGR_QCF/RefAddr/1/Type=XXX
TEST_QMGR_QCF/RefAddr/2/Content=XXXX
TEST_QMGR_QCF/RefAddr/3/Content=TEST.TEST.TLS
TEST_QMGR_QCF/RefAddr/4/Content=true
TEST_QMGR_QCF/RefAddr/5/Content=0
TEST_QMGR_QCF/RefAddr/9/Type=TCM
TEST_QMGR_QCF/RefAddr/91/Type=TM
Version of the the IBM Mq jar files used are.
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
<version>1.7.10.RELEASE</version>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mq.allclient</artifactId>
<version>9.2.2.0</version>
</dependency>
I have com.sun.jndi.fscontext.RefFSContextFactory entry to to load my .binding files in my beans.xml like below.
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">com.sun.jndi.fscontext.RefFSContextFactory</prop>
<prop key="java.naming.provider.url">file:///C:/Local</prop>
</props>
</property>
</bean>
<bean id="umConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="jndiName" value="TEST_QMGR_QCF"/>
</bean>
This is where I see with older version of Spring I was able to load the .bindings but with upgrade unable to load.
The best that I can do is to try to point you in the right direction. The .bindings file uses the com.sun.jndi.fscontext.RefFSContextFactory to provide a JNDI like lookup that is initialized from your .bindings file.
You can find some references here IBM and Sun.
Note that the jar files fscontext.jar and providerutil.jar are provided with the IBM MQ distribution in the /opt/mqm/java/lib directory. These are the Sun jars needed for the file system context. These files are not, however, provided by the com.ibm.mq.allclient maven artifact.
These jars must have been provided in your older version. You can find them in Maven Central:
<groupId>com.sun.messaging.mq</groupId>
<artifactId>fscontext</artifactId>
<packaging>jar</packaging>
<version>4.6-b01</version>
Note that the two jars seem to have been merged into the one jar in this artifact. Ensure that these Sun classes are in your current project.
Then, you'll need to find where you are doing something like (from the Sun link):
// Create the environment for constructing the initial JNDI
// naming context.
Hashtable env = new Hashtable();
// Store the environment attributes that tell JNDI which initial context
// factory to use and where to find the provider.//
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:///C:/imq_admin_objects");
// Create the initial context.
Context ctx = new InitialContext(env);
// Look up the connection factory object in the JNDI object store.
String CF_LOOKUP_NAME = "MyConnectionFactory";
ConnectionFactory myFactory = (ConnectionFactory) ctx.lookup
(CF_LOOKUP_NAME);
in your code. Note that the .bindings file name is expected, and that the location specified is a directory where the .bindings file is located.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource

I'm unable to run springboot application because of below error.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.hibernate.validator.internal.engine.ConfigurationImpl.getDefaultParameterNameProvider()Ljavax/validation/ParameterNameProvider;
Please help me.
This looks like an error caused by an illegal mix of spring versions.
Try to run mvn dependency:tree and see whether there are different versions of spring mixed in the classpath.

Spring OAuth2 implementation with InMemoryTokenStore bean creation issue

I try to implement Oauth2 into my project using this blog
I am newbie on Spring framework, so occured an exception such as ClassNotFoundException, altough all comliant classes exist under right package though.
Source (maven project) can be seen on github
Thank you
Error begins with:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.trafficalarm.rest.security.HierarchicalJsr250Voter] for bean with name 'roleVoter' defined in class path resource [spring/security/security-configuration.xml]; nested exception is java.lang.ClassNotFoundException: com.trafficalarm.rest.security.HierarchicalJsr250Voter
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.trafficalarm.rest.security.HierarchicalJsr250Voter] for bean with name 'roleVoter' defined in class path resource [spring/security/security-configuration.xml]; nested exception is java.lang.ClassNotFoundException: com.trafficalarm.rest.security.HierarchicalJsr250Voter
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.trafficalarm.rest.filter.spring.SpringCrossOriginResourceSharingFilter] for bean with name 'corsFilter' defined in class path resource [spring/oauth/oauth2-configuration.xml]; nested exception is java.lang.ClassNotFoundException: com.trafficalarm.rest.filter.spring.SpringCrossOriginResourceSharingFilter
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.trafficalarm.rest.security.OAuthRestEntryPoint] for bean with name 'oauthRestEntryPoint' defined in class path resource [spring/oauth/oauth2-configuration.xml]; nested exception is java.lang.ClassNotFoundException: com.trafficalarm.rest.security.OAuthRestEntryPoint
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
Make sure you web.xml does initialize spring context correctly:
[UPDATE]
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:app-config.xml
</param-value>
</context-param>
MUST be direct child.
Then, in your app-config you can scan for all components using
<context:component-scan base-package="your.component.package.here"/>
Then you import all of your spring config files
<import resource="classpath:your-resource.xml"/>
I also noticed that the PropertiesPlaceholderConfigurer bean was not correctly configured, so I had to do something like this on one of my spring config files, It was throwing exceptions everywhere because spring did not found the file properties:
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="WEB-INF/application.properties"/>`</bean>`
There are some classes that you won't actually need, but that is up to you. Hope you can figure it out with these hints.
Regards
The essential problem regarding the exception was the build path problem. When i moved security-configuration.xml file content into business-config.xml, ide warned me about build path problem. So i checked the build path of project, maven dependecies seem to be unchecked. I had changed version of JDK previously, so i think that caused unchecked situation. Unfortunatelly, noticing took for a while...

I am working on a spring and hibernate web application MySQLDialect not found

When i deploy it shows following error
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.quad.dao.RoleDAOImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Dialect class not found: org.hibernate.dialect.MySQLDialect
but i have hibernate jar file in lib folder.I dont understand why it is giving error.
You do not have your hibernate jar file in your classpath. Add the jars to your classpath and do a clean build.

tomcat error while running spring program

i m running hello world program in spring which works fine with eclipse but when i run it in tomcat separately it shows me error
rg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'urlMapping' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'helloController' while setting bean property 'urlMap' with key [TypedStringValue: value [/hello.html], target type [null]]; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [net.roseindia.web.HelloWorldController] for bean with name 'helloController' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: net.roseindia.web.HelloWorldController
Looks like net.roseindia.web.HelloWorldController is not in your classpath.

Resources