Just Khaithang
Just Khaithang

Reputation: 1555

Cannot find class [org.springframework.http.converter.json.Jackson2ObjMapperFactoryBean]

I am working on a simple demo project and after fixing multiple erroes now i am stuck here, bean declaration couldn't find class org.springframework.http.converter.json.Jackson2ObjMapperFactoryBean .I couldn't make head or tail of the error as i see all declared properly. May be someone experienced can point out the mistake here. A detailed explanation would be nice.

i am using spring 5.3.13 java 11 tomcat 9

Error :

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/dispatcherServlet-servlet.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: No persistence units parsed from {classpath*:META-INF/persistence.xml}
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.http.converter.json.Jackson2ObjMapperFactoryBean] for bean with name 'jsonMapper' defined in ServletContext resource [/WEB-INF/dispatcherServlet-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.http.converter.json.Jackson2ObjMapperFactoryBean
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.http.converter.json.Jackson2ObjMapperFactoryBean] for bean with name 'xmlMapper' defined in ServletContext resource [/WEB-INF/dispatcherServlet-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.http.converter.json.Jackson2ObjMapperFactoryBean

dispatcherServlet-servlet.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:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:jdbc="http://www.springframework.org/schema/jdbc"
             xsi:schemaLocation="
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
             http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
             http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
             http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/sprin-jpa-1.8.xsd
             http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">


<!-- xmlns:repository="http://www.springframework.org/schema/data/repository" -->
<!-- http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd -->
<context:component-scan base-package="org.charlie" />
<mvc:annotation-driven>
    <mvc:message-converters>
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="objectMapper" ref="jsonMapper"></property>
        </bean>
        <bean class="org.springframework.http.converter.xml.MappingJackson2xmlHttpMesssageConverter">
        <property name="objectMapper" ref="xmlMapper" />
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>
<bean id="jsonMapper" class="org.springframework.http.converter.json.Jackson2ObjMapperFactoryBean">
    <property name="simpleDateFormat" value="yyyy-MM-dd HH:mm:ss" />
</bean>

<bean id="xmlMapper" parent="jsonMapper">
    <property name="createXmlMapper" value="true"/>
</bean>

<mvc:resources mapping="/webjars/**" location="classpath:META-INF/resources/webjars/" />
<jpa:repositories base-package="org.charlie.repository" />
<jdbc:embedded-database id="dataSource" type="H2">
    <jdbc:script location="classpath:META-INF/sql/schema.sql" />
    <jdbc:script location="classpath:META-INF/sql/data.sql" />
</jdbc:embedded-database>

<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="showSql" value="true" />
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

<bean id="h2WebServer" class="org.h2.tools.Server" factory-method="createWebServer" init-method="start" destroy-method="stop">
    <constructor-arg value="-web,-webAllowOthers,-webDaemon,-webPort,8082" />
</bean>

</beans>

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-isntance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="toDo">
    <description>My Persistence Unit</description>
</persistence-unit>
</persistence>

Upvotes: 0

Views: 250

Answers (1)

Rushit Vaishnani
Rushit Vaishnani

Reputation: 296

It seems there is a typo. It should be Jackson2ObjectMapperFactoryBean instead of Jackson2ObjMapperFactoryBean.

Upvotes: 1

Related Questions