工厂方法"字符串HttpMessageConverter"抛出异常;嵌套异常是java.lang.NullPointerException



我在我的stanalone应用程序中使用了springboot spring jpa。但是我正在遵循以下错误:

由:org.springframework.beans.BeanInstantiationException: 无法实例化 [org.springframework.http.converter.stringhttpmessageconverter]: 工厂方法" stringhttpmessageconverter"丢下异常;嵌套 例外是Java.lang.nullpoInterException at org.springframework.beans.factory.support.simpleinstantiatiationstrategy.instantiate(SimpleInstantiationsTrateTrateGy.java:189) 在 org.springframework.beans.factory.support.constructorresolver.instantiateusingfactorymethod(constructorresolver.java:588) ... 69造成:Java.lang.NullPoInterException at java.nio.charset.charset.put(未知来源)at java.nio.charset.Charset.Access $ 200(未知来源) java.nio.charset.Charset $ 3.run(未知来源) java.nio.charset.Charset $ 3.run(未知来源) java.security.accesscontroller.doprivileged(本机方法) Java.nio.Charset.Charset.AvailableCharsets(未知来源) org.springframework.http.converter.stringhttpmessageconverter.(stringhttpmessageconverter.java:67) 在 在 org.springframework.boot.autoconfigure.web.httpmessageconvertersautoconfiguration $ stringhttpmessageconverterconfiguration $$ ENGHANCERBYSERBYSPRINGCGLIB $$ 在 org.springframework.boot.autoconfigure.web.httpmessageconvertersautoconfiguration $ stringhttpmessageconverterconfiguration $$ emhancerbyserbysbyspringcglib $$ 在 org.springframework.cglib.proxy.methodproxy.invokesuper(methodproxy.java:228) 在 org.springframework.context.annotation.configurationclassenhancer $ beanmethodinterceptor.intercept(configurationClassenhancer.java:309) 在 org.springframework.boot.autoconfigure.web.httpmessageconvertersautoconfiguration $ stringhttpmessageconverterconfiguration $$ emhancerBysbyspringcglib $$ 在sun.reflect.nativemethodaccessorimpl.invoke0(本机方法) sun.reflect.nativemethodaccessorimpl.invoke(未知来源) sun.reflect.delegatingmethodaccessorimpl.invoke(未知来源) java.lang.reflect.method.invoke(未知来源) org.springframework.beans.factory.support.simpleinstantiatiationstrategy.intantiate(simple instantiatiationsTrateTrateGy.java:162) ... 70

我的配置类如下:

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = {
        "com.automation.entity"
})
public class DataAccessPersistenceContext {
    @Bean
    public DataSource sybaseDataSource() {
        DataSource sybaseDataSource = new DataSource();
        try {
            sybaseDataSource.setDriverClassName("com.sybase.jdbc4.jdbc.SybDriver");
            sybaseDataSource.setUrl("jdbc:sybase:Tds:test.com:29812/TESTSCORE");
            sybaseDataSource.setUsername("testUser");
            String password = "user";
            sybaseDataSource.setPassword(password);
            sybaseDataSource.setInitialSize(Integer.parseInt("5"));
            sybaseDataSource.setMaxActive(Integer.parseInt("30"));
            sybaseDataSource.setMaxIdle(Integer.parseInt("2"));
            sybaseDataSource.setMinIdle(Integer.parseInt("2"));
            sybaseDataSource.setValidationQuery("SELECT 1");
            sybaseDataSource.setTestOnBorrow(Boolean.parseBoolean("true"));
            sybaseDataSource.setTestWhileIdle(Boolean.parseBoolean("true"));
        } catch (NumberFormatException e) {
            // log.error("Exception in CoreLocalConfig.
            // NumberFormatException:"+e);
        } catch (Exception e) {
            // log.error("Exception in CoreLocalConfig. Exception:"+e);
        }
        return sybaseDataSource;
    }
    @Bean
    @Qualifier("entityManagerFactory")
    LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
        LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
        entityManagerFactoryBean.setDataSource(dataSource);
        entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
        entityManagerFactoryBean.setPackagesToScan("com.automation.entity");
        Properties jpaProperties = new Properties();
        //Configures the used database dialect. This allows Hibernate to create SQL
        //that is optimized for the used database.
        jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.Sybase11Dialect");
        //Specifies the action that is invoked to the database when the Hibernate
        //SessionFactory is created or closed.
        jpaProperties.put("hibernate.hbm2ddl.auto", "create-drop");
        //Configures the naming strategy that is used when Hibernate creates
        //new database objects and schema elements
        jpaProperties.put("hibernate.ejb.naming_strategy", "org.hibernate.cfg.ImprovedNamingStrategy");
        //If the value of this property is true, Hibernate writes all SQL
        //statements to the console.
        jpaProperties.put("hibernate.show_sql", "true");
        //If the value of this property is true, Hibernate will format the SQL
        //that is written to the console.
        jpaProperties.put("hibernate.format_sql", "true");
        entityManagerFactoryBean.setJpaProperties(jpaProperties);
        return entityManagerFactoryBean;
    }
    @Bean
    JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(entityManagerFactory);
        return transactionManager;
    }
}

您能帮我解决这个问题吗?

我通过将正确的jconnect4.jar文件添加到classPath

来解决它。

相关内容