src/main/resource/config:
application.yml
application-dev.yml
application-sit.yml
public static void main(String[] args) {
SpringApplication app = new SpringApplication(Application.class);
SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
// Check if the selected profile has been set as argument.
// if not the development profile will be added
addDefaultProfile(app, source);
app.run(args);
}
/**
* Set a default profile if it has not been set
*/
private static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {
if (!source.containsProperty("spring.profiles.active")) {
app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);
}
}
@Configuration
public class WebAppInit implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
ApplicationContext context = new AnnotationConfigApplicationContext(Application.class);
}
}
所以我尝试了以下两种解决方案
-dspring.profiles.active=dev
添加到Tomcat/bin/catalina.sh中的JAVA_OPTSspring.profiles.active=dev
添加到Tomcat/conf/catalina.properties但两个都不起作用。如何让独立的tomcat服务器加载与spring.profiles.active属性关联的yml文件。
似乎没有设置-dspring.profiles.active=dev。
@Configuration
public class WebAppInit extends SpringBootServletInitializer {
@Override
protected WebApplicationContext createRootApplicationContext(
ServletContext servletContext) {
log.info("Properly INITALIZE spring CONTEXT");
ApplicationContext context = new AnnotationConfigApplicationContext(Application.class);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
return super.createRootApplicationContext(servletContext);
}
}
编辑2 acv:-在启动脚本中添加“--spring.profiles.active=dev”作为JAVA_OPTS变量的分隔:tomcat/bin/catalina.sh不是一个可行的选项
例如:
JAVA_OPTS="$JAVA_OPTS --spring.profiles.active=dev ...etc
spring:
profiles:
active: dev
但问题仍然发生。
编辑4:在tomcat分解的webdir下添加了application.properties:webapps/feedserver/web-inf/classes/application.properties:
spring.profiles.active=dev
spring.data.postgres.uri=jdbc:postgresql://localhost:5432/feedserver
重新启动tomcat,但问题仍然发生。
@Configuration
public class WebAppInit extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java -Djava.util.logging.config.file=/Users/shivamsinha/Desktop/Programming/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Dlog4j.rootLevel=ERROR -Dlog4j.rootAppender=console -DENV=dev -Dlog4j.configuration=/WEB-INF/classes/properties/log4j.properties -DTOMCAT_DIR=WEB-INF/classes/ -Djava.endorsed.dirs=/Users/shivamsinha/Desktop/Programming/tomcat/endorsed -classpath /Users/shivamsinha/Desktop/Programming/tomcat/bin/bootstrap.jar:/Users/shivamsinha/Desktop/Programming/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/Users/shivamsinha/Desktop/Programming/tomcat -Dcatalina.home=/Users/shivamsinha/Desktop/Programming/tomcat -Djava.io.tmpdir=/Users/shivamsinha/Desktop/Programming/tomcat/temp org.apache.catalina.startup.Bootstrap -Dspring.profiles.active=dev start
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.titlefeed.config.db.DbConfigJPA.databaseUrl; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.data.postgres.uri' in string value "${spring.data.postgres.uri}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 68 more
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.data.postgres.uri' in string value "${spring.data.postgres.uri}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:204)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:178)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:175)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:801)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:955)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 70 more
02-Sep-2015 03:15:40.472 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive /Users/shivamsinha/Desktop/Programming/tomcat/webapps/feedserver-1.0.0.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/feedserver-1.0.0]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:728)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:917)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1701)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
setenv.sh:
export SPRING_PROFILES_ACTIVE=dev
active profiles :: ${spring.profiles.active}
eval "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
-Dspring.profiles.active="\"$SPRING_PROFILE\"" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
我正在使用Vagrant部署到Ubuntu Linux,并尝试启动服务。 然后我跟踪,发现: ?tomcat8.service-lsb:启动tomcat。加载:加载(/etc/init.d/tomcat8) active:失败(结果:exit-code)自2016-03-28 09:44:17 GMT;5s前 文档:人:systemd-sysv-generator(8) 进程:884 execst
主要内容:独立服务的启动管理,独立服务的自启动管理我们知道,RPM 包默认安装的服务分为独立的服务和基于 xinetd 的服务,本节来学习独立服务的管理。 独立服务的启动管理 独立的服务要想启动,主要有两种方法。 1) 使用/etc/init.d/目录中的启动脚本来启动独立的服务 既然所有独立服务的启动脚本都存放在 /etc/init.d/ 目录中,那么,调用这些脚本就可以启动独立的服务了。这种启动方式是推荐启动方式,命令格式如下: [root@
我的代码是:
问题内容: 我正在尝试运行selenium服务器,并出现错误: 没有-r(反正是什么?) 我应该如何启动服务器? 如何设置非默认端口来收听? 这两篇文章:1 2-关于语法矛盾。我认为。 问题答案: 如果要指定端口,请执行 从3.8.1开始,不再需要指定驱动程序:
问题内容: 在我的VPS上启动selenium独立服务器时遇到麻烦 输出: 此后没有更多输出。在本地,相同的命令就像一个超级按钮一样工作。任何提示如何解决此问题? 爪哇 更新1 该服务根本不在任何端口上运行 Netstat输出 更新2 好的,这里的主要问题是selenium服务器在启动时卡住了,我不知道为什么。我销毁了我的VPS机器并从头开始。selenium服务器启动一次,在我停止并再次启动后,
我是Selenium IDE的初学者。添加了插件,并试图运行一个测试用例。它向我显示了下面的错误消息。 因此,我下载了必要的jar文件,并执行下面的命令java-jar selenium-server-standalone-2.28.0。jar[替换为下载的最新版本] 收到的信息如下:该怎么办? selenium-server-standalone-3.0.1。罐子 Java版本java版本"1.