Tomcat 및 Mysql에서 Spring과 Hibernate로 실행되는 webapp가 있습니다. 내 컴퓨터에서 코드를 작성하는 데 사용합니다. Windows 7 기반 환경 : webapp이 정상적으로 작동합니다.Windows에서 Debian으로 프로젝트를 내보낼 때의 MySQL 오류
그런 다음 원격 데비안 서버에서 내 보내서 tomcat 및 mysql을 설치 한 다음 내 Windows mysql DB에서 Dump를 가져옵니다.
내가 MySQL의 콘솔 내 데이터베이스에 액세스 할 수없는 경우에도, 내 웹 애플리케이션은 나에게이 오류 포기하지 수 :
20:35:03,020 DEBUG LogicalConnectionImpl:226 - Obtaining JDBC connection
20:35:03,021 DEBUG PoolableConnectionFactory:292 - Failed to validate a poolable connection
java.sql.SQLException: isValid() returned false
at org.apache.commons.dbcp2.PoolableConnection.validate(PoolableConnection.java:228)
at org.apache.commons.dbcp2.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:303)
at org.apache.commons.dbcp2.PoolableConnectionFactory.validateObject(PoolableConnectionFactory.java:288)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:488)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:361)
at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:119)
at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1413)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139)
그럼 내가 검색을 약
"hibernate.hbm2ddl.auto" 그래서 뭔가를 발견 내 conf에 추가 : prop.put ("hibernate.hbm2ddl.auto", "validate"); @Configuration @EnableWebSecurity AppSecurityConfig :
지금 : 여기
내 conf의 파일입니다 ...20:53:24,701 ERROR ContextLoader:331 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateMenuDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.meltdown.menu.infra.HibernateMenuDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class com.meltdown.config.ViewConfig: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.hibernate.SessionFactory com.meltdown.config.ViewConfig.sessionFactory()] threw exception; nested exception is org.hibernate.HibernateException: Missing table: BARS
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
그래서 내 응용 프로그램 내 데이터베이스에 액세스 할 수 보이지만 나는 이유를 이해 해달라고 public class AppSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
@Qualifier("userDetailsService")
UserDetailsService userDetailsService;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/bo/**").access("hasRole('ROLE_ADMIN')")
.antMatchers("/bo/bars**").access("hasRole('ROLE_SUPERADMIN')")
.and().formLogin();
}
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/resources/**");
}
@Bean
public PasswordEncoder passwordEncoder(){
PasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder;
}
}
MVCInitializer는 공용 클래스 MVCInitializer는 AbstractAnnotationConfigDispatcherServletInitializer를 확장 {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { ViewConfig.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}
ViewConfig
@EnableWebMvc
@Configuration
@ComponentScan({ "com.meltdown.*" })
@EnableTransactionManagement
@Import({ AppSecurityConfig.class })
public class ViewConfig extends WebMvcConfigurerAdapter {
@Bean
public SessionFactory sessionFactory() {
LocalSessionFactoryBuilder builder = new LocalSessionFactoryBuilder(dataSource());
builder.scanPackages("com.meltdown").addProperties(getHibernateProperties());
return builder.buildSessionFactory();
}
private Properties getHibernateProperties() {
Properties prop = new Properties();
prop.put("hibernate.format_sql", "true");
prop.put("hibernate.show_sql", "true");
prop.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
prop.put("hibernate.hbm2ddl.auto", "validate");
return prop;
}
@Bean(name = "dataSource")
public BasicDataSource dataSource() {
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("com.mysql.jdbc.Driver");
ds.setUrl("jdbc:mysql://localhost:3306/meltdown2");
ds.setUsername("root");
ds.setPassword("myXP4NYYKF8");
return ds;
}
//Create a transaction manager
@Bean
public HibernateTransactionManager txManager() {
return new HibernateTransactionManager(sessionFactory());
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/bo_theme/**");
}
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver viewResolver
= new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/pages/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
@Bean
public MultipartResolver multipartResolver() {
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setMaxUploadSize(1000000);
return resolver;
}
}
네가 맞아! 고마워요! 내 엔터티에서 @Table 주석에 소문자를 사용합니다. 그런 다음 prop.put ("hibernate.hbm2ddl.auto", "validate")을 제거합니다. 왜냐하면 그는 열 (bigint 등 대신 정수형)을 사용하고 있었기 때문에 작동합니다! – Labe