我试图在tomcat服务器上运行我的应用程序(spring + hibernate),但出现这些错误。当我注释导致错误的属性时,下一个将触发相同的错误。 我猜这些属性在初始化期间无法识别,我尝试了许多解决方案,但没有一个解决了问题。有任何人有解决这个问题的想法吗?
Stacktrace
2019-06-17 15:07:19.706 INFO 12736 --- [on(5)-127.0.0.1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 5442 ms
2019-06-17 15:07:19.737 WARN 12736 --- [on(5)-127.0.0.1] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'san.prm.webservices.config.WebConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'maxAttachmentSize' in value "${maxAttachmentSize}"
2019-06-17 15:07:19.752 INFO 12736 --- [on(5)-127.0.0.1] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2019-06-17 15:07:19.771 ERROR 12736 --- [on(5)-127.0.0.1] o.s.boot.SpringApplication : Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'san.prm.webservices.config.WebConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'maxAttachmentSize' in value "${maxAttachmentSize}"
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169) [spring-web-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5244) [catalina.jar:8.0.32]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) [catalina.jar:8.0.32]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725) [catalina.jar:8.0.32]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701) [catalina.jar:8.0.32]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717) [catalina.jar:8.0.32]
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1692) [catalina.jar:8.0.32]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) [tomcat-coyote.jar:8.0.32]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [na:1.8.0_161]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [na:1.8.0_161]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:465) [catalina.jar:8.0.32]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:415) [catalina.jar:8.0.32]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) [tomcat-coyote.jar:8.0.32]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [na:1.8.0_161]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [na:1.8.0_161]
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) [na:1.8.0_161]
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) [na:1.8.0_161]
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) [na:1.8.0_161]
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) [na:1.8.0_161]
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) [na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:361) [na:1.8.0_161]
at sun.rmi.transport.Transport$1.run(Transport.java:200) [na:1.8.0_161]
at sun.rmi.transport.Transport$1.run(Transport.java:197) [na:1.8.0_161]
at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_161]
at sun.rmi.transport.Transport.serviceCall(Transport.java:196) [na:1.8.0_161]
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) [na:1.8.0_161]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) [na:1.8.0_161]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) [na:1.8.0_161]
at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_161]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) [na:1.8.0_161]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_161]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_161]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_161]
WebConfig.java
@Configuration
@Import( { CoreConfig.class, PRMKeycloakRestClientConfiguration.class } )
@ComponentScan(basePackages = { "san.prm.webservices.controller", "san.prm.webservices.authentication"})
public class WebConfig {
@Value("${maxAttachmentSize}")
private long maxAttachmentSize;
@Bean
public ErrorPageFilter errorPageFilter() {
return new ErrorPageFilter();
}
@Bean
public FilterRegistrationBean disableSpringBootErrorFilter(ErrorPageFilter filter) {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(filter);
filterRegistrationBean.setEnabled(false);
return filterRegistrationBean;
}
@Bean
public ExceptionStatusService exceptionStatusService() {
ExceptionStatusServiceImpl service = new ExceptionStatusServiceImpl();
service.setDefaultStatus(HttpStatus.BAD_REQUEST);
service.setExceptionStatus(getMappings());
return service;
}
private Map<Class<? extends PRMException>, HttpStatus> getMappings() {
...
}
@Bean
public Module jacksonPageWithJsonViewModule() {
SimpleModule module = new SimpleModule("jackson-page-with-jsonview", Version.unknownVersion());
module.addSerializer(Page.class, new PageSerializer());
return module;
}
Initializer.java
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {"san.prm.webservices.controller"})
@EnableCaching
@EnableTransactionManagement
@Import({ WebConfig.class, WebSecurityConfig.class })
public class Initializer extends SpringBootServletInitializer implements WebApplicationInitializer {
}
app.properties
commonFilePath=${prm.app.commonfilepath}
maxAttachmentSize=${prm.app.maxattachmentsize}
documentFilePath=${prm.app.documentfilepath}
modeleDocumentFilePath=${prm.app.modeledocumentfilepath}
singleKey.keystore.path=${prm.app.singleKey.keystore.path}
genericPush.enabled=${prm.app.genericPush.enabled}
genericPush.keystore.path=${prm.app.genericPush.keystore.path}
genericPush.requester=${prm.app.genericPush.requester}
genericPush.stream=${prm.app.genericPush.stream}
genericPush.url=${prm.app.genericPush.url}
droitsFormulaires.enabled=false
clamav.host=${prm.app.clamav.host}
clamav.port=${prm.app.clamav.port}
答案 0 :(得分:0)
您是否尝试过将“ app.properties”文件重命名为“ application.properties”? 该文件的路径是什么?如果您不想手动配置其路径,则它必须位于“资源”目录下。
答案 1 :(得分:0)
确保属性文件位于资源中,并且在编译过程中正在复制它。
此外,名称也必须是application.properties或application- {profile} .properties。阅读此以获得更多信息。
Configuration | Spring Framework Docs
如果没有,则可以使用@PropertySource来指定属性文件(如果不按照约定或外部配置命名)。
答案 2 :(得分:0)
我有app.properties和application.properties,我在application.properties中收集了这两个文件,并删除了另一个,但它没有任何改变。该文件位于“资源”目录中,似乎可以被Intellij识别。
我在pom.xml中添加了它
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>
和WebConfig中的下一行,但仍然相同。
@PropertySource("classpath:/application.properties")
我要运行的应用程序是使用完全相同的属性并且运行良好的应用程序的分支。
答案 3 :(得分:0)
通过在pom中添加此行来解决
<filtering>true</filtering>
为此
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>