0
我想與Tomee運行Spring mvc註釋配置。 我沒有在我的項目的任何XML配置,但我有hme標註配置在tomee:缺少必需的persistence.xml
缺少必要的persistence.xml
這是我的配置文件
@EnableTransactionManagement
@Configuration
@EnableWebMvc
@ComponentScan({"controller","service","model"})
public class AppConfig extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver configureViewResolvers() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver ;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
}
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages");
return messageSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[]{"model"});
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties());
return em;
}
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://localhost:5432/e");
dataSource.setUsername("postgres");
dataSource.setPassword("admin");
return dataSource;
}
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
private final Properties additionalProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.hbm2ddl.auto","create");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
return properties;
}
}
和堆棧跟蹤
31-May-2017 16:52:39.386 SEVERE [http-nio-8080-exec-4] org.apache.openejb.config.ReportValidationResults.logResults FAIL ... EE-System-0.8.0: Missing required persistence.xml for @PersistenceContext ref "java:comp/env/aa" to unit ""
31-May-2017 16:52:39.387 SEVERE [http-nio-8080-exec-4] org.apache.openejb.config.ReportValidationResults.logResults Invalid EjbModule(name=EE-System-0.8.0, path=D:\ee-system\ear\target\ear-1.0-SNAPSHOT\EE-System-0.8.0)
31-May-2017 16:52:39.388 SEVERE [http-nio-8080-exec-4] org.apache.openejb.config.ReportValidationResults.logResults FAIL ... ee: Missing required persistence.xml for @PersistenceContext ref "java:comp/env/aa" to unit ""
31-May-2017 16:52:39.390 SEVERE [http-nio-8080-exec-4] org.apache.openejb.config.ReportValidationResults.logResults Invalid WebModule(name=EE-System-0.8.0, path=D:\ee-system\ear\target\ear-1.0-SNAPSHOT\EE-System-0.8.0)
31-May-2017 16:52:39.391 INFO [http-nio-8080-exec-4] org.apache.openejb.config.ReportValidationResults.deploy Set the 'openejb.validation.output.level' system property to VERBOSE for increased validation details.
31-May-2017 16:52:39.881 SEVERE [http-nio-8080-exec-4] org.apache.openejb.assembler.DeployerEjb.deploy Can't deploy D:\ee-system\ear\target\ear-1.0-SNAPSHOT.ear
org.apache.openejb.config.ValidationFailedException: Module failed validation. AppModule(name=ear-1.0-SNAPSHOT)
at org.apache.openejb.config.ReportValidationResults.deploy(ReportValidationResults.java:88)
at org.apache.openejb.config.AppInfoBuilder.build(AppInfoBuilder.java:321)
at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:1040)
at org.apache.openejb.assembler.DeployerEjb.deploy(DeployerEjb.java:244)
at org.apache.openejb.assembler.DeployerEjb.deploy(DeployerEjb.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:205)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:186)
at org.apache.openejb.security.internal.InternalSecurityInterceptor.invoke(InternalSecurityInterceptor.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:205)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:186)
at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:181)
at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:205)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:186)
at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:85)
at org.apache.openejb.core.singleton.SingletonContainer._invoke(SingletonContainer.java:256)
at org.apache.openejb.core.singleton.SingletonContainer.invoke(SingletonContainer.java:212)
at org.apache.openejb.server.ejbd.EjbRequestHandler.doEjbObject_BUSINESS_METHOD(EjbRequestHandler.java:371)
at org.apache.openejb.server.ejbd.EjbRequestHandler.processRequest(EjbRequestHandler.java:182)
at org.apache.openejb.server.ejbd.EjbDaemon.processEjbRequest(EjbDaemon.java:360)
at org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:247)
at org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java:104)
at org.apache.openejb.server.httpd.ServerServlet.service(ServerServlet.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.tomee.catalina.OpenEJBSecurityListener$RequestCapturer.invoke(OpenEJBSecurityListener.java:97)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
任何想法和幫助讚賞。
感謝您的重播。 – Generic