java - 如何在 websphere liberty 8.5 中设置 spring.profiles.active

标签 java spring jvm websphere websphere-liberty

当我尝试使用 jvm.options 文件启动 Websphere 时,为什么会收到错误“无法识别的选项:-spring.profiles.active=development”?我正在按照 http://www-01.ibm.com/support/docview.wss?uid=swg21596474 中提供的步骤进行操作。

实际上,我希望将 Websphere Liberty Profile 添加到 Eclipse Server View,就像我对 Tomcat 所做的那样。在 Tomcat 8 中,我刚刚在 catalina.properties 中添加了“spring.profiles.active=development”,它与我以“mvn ... -Dspring.profiles.active=development”开头的效果相同。

我将我的问题视为开发人员主题,因为我想知道如何利用 @profile 启动 Websphere Liberty Profile。

请务必了解我正在使用 Websphere Liberty,这意味着我没有 Websphere 管理控制台,因此,如果有人在 Websphere 管理控制台屏幕中提供步骤,那么它将毫无值(value)。

我添加了一个图像来显示我的 Eclipse Server View 如何以及我在哪里添加了仅包含 -spring.profiles.active=development 的 jvm.options 文件。

仅当我尝试使用此类 jvm.otions 启动服务器时,才会出现该错误。如果我取出文件,服务器就会启动,但显然,当我添加我的应用程序时,@profile 将不会被考虑在内。

整个错误:

Error: Could not create the Java Virtual Machine.

Error: A fatal exception has occurred. Program will exit.

Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0

Unrecognized option: -spring.profiles.active=development

附注我认为这与我的问题无关,顺便说一句,整个应用程序可以在 https://github.com/jhades/spring-mvc-angularjs-sample-app 中找到

Eclipse Server view

*** 已编辑 1

按照建议在“-”后添加“D”后,我可以启动服务器(在 Tomcat 中有所不同,因为在 Tomcat 中必须避免“D”)。顺便说一句,当我将应用程序部署到 WAS Liberty 时,我根本没有看到 @profile 生效。我在下面添加了整个 Websphere 日志,但没有看到与 Tomcat 中通常看到的相同的长日志描述。由于我面临与上下文路径相关的额外错误(请参阅附加的新图像),因此除了看到欢迎页面之外,我无法测试该应用程序,但我几乎可以肯定 @profile 被忽略了,因为日志似乎不是这样已考虑在内。

********************************************************************************

product = WebSphere Application Server 8.5.5.9 (wlp-1.0.12.cl50920160227-1523)

wlp.install.dir = C:/Users/my_user/WasWebDownloadedFromEclipse/

java.home = C:\Program Files\Java\jdk1.8.0_65\jre

java.version = 1.8.0_65

java.runtime = Java(TM) SE Runtime Environment (1.8.0_65-b17)

os = Windows 7 (6.1; amd64) (en_US)

process = 6780@GH-VDIKCISV252

********************************************************************************

[7/7/16 16:13:04:151 CDT] 00000001 com.ibm.ws.kernel.launch.internal.FrameworkManager           A CWWKE0001I: The server srvFromDefaultLink has been launched.

[7/7/16 16:13:04:175 CDT] 00000001 com.ibm.ws.kernel.launch.internal.FrameworkManager           A CWWKE0100I: This product is licensed for development, and limited production use. The full license terms can be viewed here: https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/license/base_ilan/ilan/8.5.5.9/lafiles/en.html

[7/7/16 16:13:07:531 CDT] 00000001 com.ibm.ws.kernel.launch.internal.FrameworkManager           I CWWKE0002I: The kernel started after 3.998 seconds

[7/7/16 16:13:07:727 CDT] 00000017 com.ibm.ws.kernel.feature.internal.FeatureManager            I CWWKF0007I: Feature update started.

[7/7/16 16:13:09:941 CDT] 00000010 com.ibm.ws.security.ready.internal.SecurityReadyServiceImpl  I CWWKS0007I: The security service is starting...

[7/7/16 16:13:11:591 CDT] 00000018 com.ibm.ws.security.token.ltpa.internal.LTPAKeyCreator       I CWWKS4105I: LTPA configuration is ready after 0.406 seconds.

[7/7/16 16:13:12:599 CDT] 00000010 com.ibm.ws.app.manager.internal.monitor.DropinMonitor        A CWWKZ0058I: Monitoring dropins for applications.

[7/7/16 16:13:13:904 CDT] 0000001d com.ibm.ws.tcpchannel.internal.TCPChannel                    I CWWKO0219I: TCP Channel defaultHttpEndpoint has been started and is now listening for requests on host 127.0.0.1  (IPv4: 127.0.0.1) port 8080.

[7/7/16 16:13:17:499 CDT] 00000010 com.ibm.ws.cache.ServerCache                                 I DYNA1001I: WebSphere Dynamic Cache instance named baseCache initialized successfully.

[7/7/16 16:13:17:502 CDT] 00000010 com.ibm.ws.cache.ServerCache                                 I DYNA1071I: The cache provider default is being used.

[7/7/16 16:13:17:503 CDT] 00000010 com.ibm.ws.cache.CacheServiceImpl                            I DYNA1056I: Dynamic Cache (object cache) initialized successfully.

[7/7/16 16:13:19:346 CDT] 00000017 com.ibm.ws.kernel.feature.internal.FeatureManager            A CWWKF0012I: The server installed the following features: [jsp-2.3, ejbLite-3.2, managedBeans-1.0, jsf-2.2, beanValidation-1.1, servlet-3.1, ssl-1.0, jndi-1.0, localConnector-1.0, jsonp-1.0, appSecurity-2.0, jdbc-4.1, jaxrs-2.0, jaxrsClient-2.0, el-3.0, json-1.0, cdi-1.2, distributedMap-1.0, webProfile-7.0, websocket-1.1, jpa-2.1].

[7/7/16 16:13:19:347 CDT] 00000017 com.ibm.ws.kernel.feature.internal.FeatureManager            I CWWKF0008I: Feature update completed in 11.807 seconds.

[7/7/16 16:13:19:348 CDT] 00000017 com.ibm.ws.kernel.feature.internal.FeatureManager            A CWWKF0011I: The server srvFromDefaultLink is ready to run a smarter planet.

[7/7/16 16:13:44:452 CDT] 00000017 com.ibm.ws.config.xml.internal.ConfigRefresher               A CWWKG0016I: Starting server configuration update.

[7/7/16 16:13:44:605 CDT] 00000018 com.ibm.ws.app.manager.AppMessageHelper                      W CWWKZ0014W: The application spring-mvc-angularjs-sample-app-master could not be started as it could not be found at location spring-mvc-angularjs-sample-app-master.war.

[7/7/16 16:13:44:606 CDT] 00000017 com.ibm.ws.config.xml.internal.ConfigRefresher               A CWWKG0017I: The server configuration was successfully updated in 0.311 seconds.

[7/7/16 16:13:45:227 CDT] 00000017 com.ibm.ws.app.manager.AppMessageHelper                      I CWWKZ0018I: Starting application spring-mvc-angularjs-sample-app-master.

[7/7/16 16:13:53:746 CDT] 00000017 org.jboss.weld.Version                                       I WELD-000900: SNAPSHOT

[7/7/16 16:14:15:269 CDT] 00000018 com.ibm.ws.app.manager.AppMessageHelper                      A CWWKZ0022W: Application spring-mvc-angularjs-sample-app-master has not started in 30.042 seconds.

[7/7/16 16:14:25:297 CDT] 00000017 com.ibm.ws.webcontainer.osgi.webapp.WebGroup                 I SRVE0169I: Loading Web Module: Archetype Created Web Application.

[7/7/16 16:14:25:302 CDT] 00000017 com.ibm.ws.webcontainer                                      I SRVE0250I: Web Module Archetype Created Web Application has been bound to default_host.

[7/7/16 16:14:25:304 CDT] 00000017 com.ibm.ws.http.internal.VirtualHostImpl                     A CWWKT0016I: Web application available (default_host): http://localhost:8080/calories-tracker/

[7/7/16 16:14:25:309 CDT] 00000017 com.ibm.ws.app.manager.AppMessageHelper                      A CWWKZ0001I: Application spring-mvc-angularjs-sample-app-master started in 40.082 seconds.

[7/7/16 16:16:53:905 CDT] 0000002b com.ibm.ws.session.WASSessionCore                            I SESN8501I: The session manager did not find a persistent storage location; HttpSession objects will be stored in the local application server's memory.

[7/7/16 16:16:53:912 CDT] 0000002b com.ibm.ws.session.WASSessionCore                            I SESN0176I: A new session context will be created for application key default_host/calories-tracker

[7/7/16 16:16:54:017 CDT] 0000002b com.ibm.ws.util                                              I SESN0172I: The session manager is using the Java default SecureRandom implementation for session ID generation.

[7/7/16 16:16:54:089 CDT] 0000002b com.ibm.ws.jsp                                               I JSPG8502I: The value of the JSP attribute jdkSourceLevel is "15".

[7/7/16 16:16:54:483 CDT] 0000002b com.ibm.ws.cache.CacheServiceImpl                            I DYNA1056I: Dynamic Cache (object cache) initialized successfully.

[7/7/16 16:16:55:462 CDT] 0000002b com.ibm.ws.webcontainer.webapp                               I SRVE0292I: Servlet Message - [spring-mvc-angularjs-sample-app-master]:.Spring WebApplicationInitializers detected on classpath: [calories.tracker.config.SecurityWebApplicationInitializer@23cbd857, calories.tracker.config.WebAppInitializer@7c711eb2]

[7/7/16 16:16:55:606 CDT] 0000002b com.ibm.ws.webcontainer.webapp                               I SRVE0292I: Servlet Message - [spring-mvc-angularjs-sample-app-master]:.Initializing Spring root WebApplicationContext

[7/7/16 16:16:55:607 CDT] 0000002b org.springframework.web.context.ContextLoader                I Root WebApplicationContext: initialization started

[7/7/16 16:16:55:678 CDT] 0000002b rk.web.context.support.AnnotationConfigWebApplicationContext I Refreshing Root WebApplicationContext: startup date [Thu Jul 07 16:16:55 CDT 2016]; root of context hierarchy

[7/7/16 16:16:55:708 CDT] 0000002b rk.web.context.support.AnnotationConfigWebApplicationContext I Registering annotated classes: [class calories.tracker.config.root.RootContextConfig,class calories.tracker.config.root.DevelopmentConfiguration,class calories.tracker.config.root.TestConfiguration,class calories.tracker.config.root.AppSecurityConfig]

[7/7/16 16:16:56:578 CDT] 0000002b eans.factory.annotation.AutowiredAnnotationBeanPostProcessor I JSR-330 'javax.inject.Inject' annotation found and supported for autowiring

[7/7/16 16:16:56:838 CDT] 0000002b org.springframework.jdbc.datasource.DriverManagerDataSource  I Loaded JDBC driver: org.postgresql.Driver

[7/7/16 16:16:56:958 CDT] 0000002b ringframework.orm.jpa.LocalContainerEntityManagerFactoryBean I Building JPA container EntityManagerFactory for persistence unit 'default'

[7/7/16 16:17:02:203 CDT] 0000002b org.springframework.security.web.DefaultSecurityFilterChain  I Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@297728f1, org.springframework.security.web.context.SecurityContextPersistenceFilter@724560fb, org.springframework.security.web.header.HeaderWriterFilter@d397b67, org.springframework.security.web.csrf.CsrfFilter@f62a487, com.allanditzel.springframework.security.web.csrf.CsrfTokenResponseHeaderBindingFilter@10fd6c23, org.springframework.security.web.authentication.logout.LogoutFilter@5ed9a45a, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@625bbf32, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@266bef7, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@343dbd9e, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@6a796e81, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@198ef120, org.springframework.security.web.session.SessionManagementFilter@79951250, org.springframework.security.web.access.ExceptionTranslationFilter@558e68b7, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@639c2328]

[7/7/16 16:17:02:250 CDT] 0000002b org.springframework.web.context.ContextLoader                I Root WebApplicationContext: initialization completed in 6629 ms

[7/7/16 16:17:02:294 CDT] 0000002b com.ibm.ws.webcontainer.webapp                               I SRVE0292I: Servlet Message - [spring-mvc-angularjs-sample-app-master]:.Initializing Spring FrameworkServlet 'dispatcher'

[7/7/16 16:17:02:294 CDT] 0000002b org.springframework.web.servlet.DispatcherServlet            I FrameworkServlet 'dispatcher': initialization started

[7/7/16 16:17:02:321 CDT] 0000002b rk.web.context.support.AnnotationConfigWebApplicationContext I Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Thu Jul 07 16:17:02 CDT 2016]; parent: Root WebApplicationContext

[7/7/16 16:17:02:329 CDT] 0000002b rk.web.context.support.AnnotationConfigWebApplicationContext I Registering annotated classes: [class calories.tracker.config.servlet.ServletContextConfig]

[7/7/16 16:17:02:541 CDT] 0000002b eans.factory.annotation.AutowiredAnnotationBeanPostProcessor I JSR-330 'javax.inject.Inject' annotation found and supported for autowiring

[7/7/16 16:17:03:584 CDT] 0000002b b.servlet.mvc.method.annotation.RequestMappingHandlerMapping I Mapped "{[/lifecycle],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void calories.tracker.app.controllers.LifeCycleController.createLifeCycle(calories.tracker.app.dto.LifeCycleDTO)

[7/7/16 16:17:03:586 CDT] 0000002b b.servlet.mvc.method.annotation.RequestMappingHandlerMapping I Mapped "{[/meal],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public calories.tracker.app.dto.MealsDTO calories.tracker.app.controllers.MealController.searchMealsByDate(java.security.Principal,java.util.Date,java.util.Date,java.util.Date,java.util.Date,java.lang.Integer)

[7/7/16 16:17:03:587 CDT] 0000002b b.servlet.mvc.method.annotation.RequestMappingHandlerMapping I Mapped "{[/meal],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.util.List<calories.tracker.app.dto.MealDTO> calories.tracker.app.controllers.MealController.saveMeals(java.security.Principal,java.util.List<calories.tracker.app.dto.MealDTO>)

[7/7/16 16:17:03:588 CDT] 0000002b b.servlet.mvc.method.annotation.RequestMappingHandlerMapping I Mapped "{[/meal],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void calories.tracker.app.controllers.MealController.deleteMeals(java.util.List<java.lang.Long>)

[7/7/16 16:17:03:592 CDT] 0000002b b.servlet.mvc.method.annotation.RequestMappingHandlerMapping I Mapped "{[/user],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public calories.tracker.app.dto.UserInfoDTO calories.tracker.app.controllers.UserController.getUserInfo(java.security.Principal)

[7/7/16 16:17:03:593 CDT] 0000002b b.servlet.mvc.method.annotation.RequestMappingHandlerMapping I Mapped "{[/user],methods=[PUT],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void calories.tracker.app.controllers.UserController.updateUserMaxCaloriesPerDay(java.security.Principal,java.lang.Long)

[7/7/16 16:17:03:597 CDT] 0000002b b.servlet.mvc.method.annotation.RequestMappingHandlerMapping I Mapped "{[/user],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void calories.tracker.app.controllers.UserController.createUser(calories.tracker.app.dto.NewUserDTO)

[7/7/16 16:17:03:656 CDT] 0000002b .springframework.web.servlet.handler.SimpleUrlHandlerMapping I Mapped URL path [/resources/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

[7/7/16 16:17:03:953 CDT] 0000002b b.servlet.mvc.method.annotation.RequestMappingHandlerAdapter I Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Thu Jul 07 16:17:02 CDT 2016]; parent: Root WebApplicationContext

[7/7/16 16:17:04:235 CDT] 0000002b org.springframework.web.servlet.DispatcherServlet            I FrameworkServlet 'dispatcher': initialization completed in 1940 ms

[7/7/16 16:17:04:235 CDT] 0000002b com.ibm.ws.webcontainer.servlet                              I SRVE0242I: [spring-mvc-angularjs-sample-app-master] [/calories-tracker] [dispatcher]: Initialization successful.

个人资料(“开发”)可能被忽略

@Configuration
@Profile("development")
@EnableTransactionManagement
public class DevelopmentConfiguration {
    @Bean(name = "datasource")
    public DriverManagerDataSource dataSource() {
...
    @Bean(name = "entityManagerFactory")
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(DriverManagerDataSource dataSource) 
...

This is an error with context path blocking me to test the application

最佳答案

  • 通过命令行传递给 java 的 JVM 参数应以 -D 开头

    -Dspring.profiles.active=development
    
  • 通过 jvm.options 传递的 JVM 参数应以 -D 开头

  • 通过 catalina.properties 传递的 JVM 参数不需要以 -D 为前缀

关于java - 如何在 websphere liberty 8.5 中设置 spring.profiles.active,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38254271/

相关文章:

multithreading - 理解JVM的 "Attach Listener"线程

spring - 我应该将我的 Vaadin 10+ 静态文件放在哪里?

java - 将@Context参数传递给类中的方法

java - JVM线程调度算法是什么?

java - asm 字节码中的字符串相等性

java - Spring - 使用 Web 服务时未加载属性文件中的值

java - 求n个数的gcd

java - 如何制作泛型的构造函数

具有 CompletableFuture 的 Java 8 线程 : Shutdown after supplyAsync()?

java - hibernate +JPA : Schema-validation: missing column