我在stanalone应用程序中使用Springboot + Spring JPA。但我正在跟踪错误:
引起:org.springframework.beans.BeanInstantiationException: 无法实例化 [org.springframework.http.converter.StringHttpMessageConverter]: 工厂方法' stringHttpMessageConverter'抛出异常;嵌套 异常是java.lang.NullPointerException org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.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(未知来源)at java.nio.charset.Charset $ 3.run(未知来源)at java.nio.charset.Charset $ 3.run(未知来源)at java.security.AccessController.doPrivileged(Native Method)at java.nio.charset.Charset.availableCharsets(未知来源)at org.springframework.http.converter.StringHttpMessageConverter。(StringHttpMessageConverter.java:67) 在 org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration $ StringHttpMessageConverterConfiguration.stringHttpMessageConverter(HttpMessageConvertersAutoConfiguration.java:77) 在 org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration $ StringHttpMessageConverterConfiguration $$ EnhancerBySpringCGLIB $$ 4ce1453d.CGLIB $ stringHttpMessageConverter $ 0() 在 org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration $ StringHttpMessageConverterConfiguration $$ EnhancerBySpringCGLIB $$ 4ce1453d $$ FastClassBySpringCGLIB $$ 1235f10b.invoke() 在 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 $$ EnhancerBySpringCGLIB $$ 4ce1453d.stringHttpMessageConverter() at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at java.lang.reflect.Method.invoke(未知来源)at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ......还有70多个
我的Config课程如下:
@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;
}
}
你能帮我解决这个问题吗?
答案 0 :(得分:0)
我已经通过将正确的jconnect4.jar文件添加到类路径
中来解决它