我在弹簧工具套件中制作的MVC弹簧项目中出现此错误。 显然java文件存在,那里没有编译错误,我也包含了相应的jar。测试的独立程序运行正常,但是当我尝试在测试服务器上发布时,网页显示HTTP 500状态错误。
我用spring创建了另一个默认的web项目,它运行,服务器显示主页,我用这个模板创建我自己的项目,因为我没有触及与webserver无关的配置文件(只有spring和hibernate xml文件)我不知道为什么我得到这个。
以下是来自堆栈跟踪的完整消息(仅错误)
HTTP 500状态 - servlet的Servlet.init()抛出异常appServlet
org.springframework.beans.factory.BeanDefinitionStoreException:无法加载bean类:mvc.test.hib.hibernateConfig;
嵌套异常是java.io.FileNotFoundException:无法打开类路径资源[org / springframework / transaction / annotation / EnableTransactionManagement.class],因为它不存在
这里提到的java文件应该是错误
package mvc.test.hib;
import java.util.Properties;
import javax.sql.DataSource;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableTransactionManagement
@ComponentScan({"mvc.test.hib" })
@PropertySource(value = { "classpath:application.properties" })
public class hibernateConfig {
@Autowired
private Environment environment;
@Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan(new String[] { "mvc.test.hib" });
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
return dataSource;
}
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
return properties;
}
@Bean
@Autowired
public HibernateTransactionManager transactionManager(SessionFactory s) {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(s);
return txManager;
}
}
编辑:我知道我错了,因为我没有添加Jar,我下载了包含 org / springframework / transaction / annotation / EnableTransactionManagement.class 的jar,仍然是一样的信息。我迷路了。
我没有使用maven,所有罐子都是手动导入的