Multiple Spring profiles for xml properties files? - spring

Im wanting to feed multiple configuration files based on properties into –
<beans:property name="locations">
<beans:list>
<beans:value>classpath:properties/local.properties</beans:value>
<beans:value>classpath:properties/${spring.profiles.active}.properties</beans:value>
</beans:list>
</beans:property>
And was under the impression I could use –
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>profile-a, profile-b</param-value>
</context-param>
I get this error – so its not parsing the param-values -
14:13:12.065 [localhost-startStop-1] TRACE o.s.c.e.PropertySourcesPropertyResolver - getProperty("spring.profiles.active", String)
14:13:12.065 [localhost-startStop-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.profiles.active' in [servletConfigInitParams]
14:13:12.065 [localhost-startStop-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.profiles.active' in [servletContextInitParams]
14:13:12.065 [localhost-startStop-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 'spring.profiles.active' in [servletContextInitParams] with type [String] and value profile-a, profile-b'
14:13:12.065 [localhost-startStop-1] TRACE o.s.util.PropertyPlaceholderHelper - Resolved placeholder 'spring.profiles.active'
14:13:12.065 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'dsProperties'
14:13:12.065 [localhost-startStop-1] INFO o.s.b.f.config.PropertiesFactoryBean - Loading properties file from class path resource [properties/profile-a, profile-b.properties]
14:13:12.065 [localhost-startStop-1] WARN o.s.b.f.config.PropertiesFactoryBean - Could not load properties from class path resource [properties/ profile-a, profile-b.properties.properties]: class path
Can this be done?

Related

Spring Boot 1.4 not loading application.properties after upgrade

I am in process of upgrading a spring boot 1.3.3 project to 1.4.2.
After upgrading the project Spring boot will no longer use any application.properties file. It does not locate it. Even when passed as an startup argument.
The project is built with gradle and a shadowjar plugin to compile to a fat jar and start tomcat embedded from the jar.
The way the application is started is: java -jar app-all.jar. The directory containing the jar also contains the application.properties file. (and no other files)
There is no classpath set and the jar file does not contain any other application.properties files. (Tested with unzip -t app-all.jar |grep application.properties)
Starting the project under Spring Boot 1.3.3. The application starts correctly. Start of log file:
04:15:58.846 com.app.MaxApplication INFO [main] - Starting MaxApplication on test-ng with PID 30096 (/home/ubuntu/app-all.jar started by ubuntu in /home/ubuntu)
04:15:58.850 com.app.MaxApplication DEBUG [main] - Running with Spring Boot, Spring
04:15:58.850 com.app.MaxApplication INFO [main] - The following profiles are active: TEST
04:15:58.850 org.springframework.boot.SpringApplication DEBUG [main] - Loading source class com.app.MaxApplication
04:15:58.947 org.springframework.boot.context.config.ConfigFileApplicationListener DEBUG [main] - Activated profiles TEST
04:15:58.947 org.springframework.boot.context.config.ConfigFileApplicationListener DEBUG [main] - Loaded config file 'file:./application.properties'
Changing spring boot version to 1.4.2, cleaning gradle caches and rebuilding and running the application the same way Spring Boot does nto load the applciation.properties file and the application fails to start due to missing configuration settings provided by the file. Start of log file:
01:48:47.547 [main] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [servletConfigInitParams] PropertySource with lowest search precedence
01:48:47.549 [main] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [servletContextInitParams] PropertySource with lowest search precedence
01:48:47.551 [main] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
01:48:47.552 [main] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
01:48:47.552 [main] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,systemProperties,systemEnvironment]
01:48:47.552 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'spring.profiles.active' in any property source
01:48:47.552 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'spring.profiles.active' in any property source
01:48:47.554 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'banner.image.location' in any property source
01:48:47.555 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'banner.location' in any property source
01:48:47.556 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'banner.charset' in any property source
01:48:47.557 [main] DEBUG org.springframework.core.env.MutablePropertySources - Adding [version] PropertySource with lowest search precedence
01:48:47.560 [main] DEBUG org.springframework.core.env.MutablePropertySources - Adding [ansi] PropertySource with highest search precedence
01:48:47.561 [main] DEBUG org.springframework.core.env.MutablePropertySources - Adding [title] PropertySource with highest search precedence
01:48:47.600 [main] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [servletConfigInitParams] PropertySource with lowest search precedence
01:48:47.600 [main] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [servletContextInitParams] PropertySource with lowest search precedence
01:48:47.600 [main] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
01:48:47.600 [main] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
01:48:47.601 [main] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,systemProperties,systemEnvironment]
01:48:47.637 [main] DEBUG org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
01:48:47.649 [main] INFO com.app.MaxApplication - Starting MaxApplication on test-ng (/home/ubuntu/app-all.jar started by ubuntu in /home/ubuntu)
01:48:47.649 [main] DEBUG com.app.max.MaxApplication - Running with Spring Boot, Spring
01:48:47.650 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'spring.profiles.active' in any property source
01:48:47.650 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'spring.profiles.default' in any property source
01:48:47.650 [main] INFO com.app.max.MaxApplication - No active profile set, falling back to default profiles: default
01:48:47.650 [main] DEBUG org.springframework.boot.SpringApplication - Loading source class com.app.MaxApplication
Only two files in the current directory are the application.properties file and the jar file. The externalizing configration documentation says the configuration should be read from there. It also works under Spring 1.3.3
I have defined a configuration class (this is working in 1.3)
#Component
#Configuration
#SpringBootConfiguration
public class MaxApplicationProperties {
#Bean
public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
I have tried:
Adding application.properties file to the class path.
Starting the application with --spring.config.location=application.properties (and with full path as well)
Setting config location environment variables.
Adding annotation #PropertySource("classpath:application.properties") to the MaxApplicationProperties class
Force deleting all downloaded libraries and having gradle re-download everything.
None of these options work to make Spring boot attempt to use the application.properties file the same was as Spring boot 1.3.
Anyone know what I am missing? Thanks.

Connecting to Filenet running on Websphere 8.5 via EJB transport using Spring Boot with Embedded Tomcat

I’m developing a Spring Boot app using Filenet CEAPI with EJB transport (the Filenet Web Service (CEWS) connection is not an options), but when I try to run my spring boot app, I get the following error over and over again in every second:
NMSV0307E: A java: URL name was used, but Naming was not configured to
handle java: URL names. The likely cause is a user in error attempting
to specify a java: URL name in a non-J2EE client or server
environment. Throwing ConfigurationException.
My config is:
spring.version = 4.2.2.RELEASE
spring.boot.version = 1.2.7.RELEASE
(I’ve tried 1.4.0.RELEASE, but I got the same results)
Websphere = 8.5 - this runs the Filenet Content Engine
Filenet & CEAPI = 5.2.1 - using EJB connection
I've used tutorial: http://www.notonlyanecmplace.com/how-to-connect-via-ejb-to-p8-5-2-and-websphere-v8-5/
I’ve enabled Tomcat JNDI naming using this Stackoverflow entry:
How to create JNDI context in Spring Boot with Embedded Tomcat Container
Although adding a breakpoint at the tomcat.enableNaming(); line does not stop...
I’m using this part of this solution:
#Bean
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
return new TomcatEmbeddedServletContainerFactory() {
#Override
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(
Tomcat tomcat) {
tomcat.enableNaming();
return super.getTomcatEmbeddedServletContainer(tomcat);
}
};
}
I don’t use the rest, since I don’t want to lookup anything via JNDI, since Filenet API does that.
So to summarize it: could someone please tell me how to connect to a Filenet running on a Websphere 8.5 appserver via Filenet Java API over EJB transport protocol using Spring Boot 1.2.7 and Embedded Tomcat?
EDIT:
The Filenet API uses the following files optained from the Websphere server:
com.ibm.ws.orb_8.5.0.jar
com.ibm.ws.ejb.thinclient_8.5.0
key.p12
sas.client.props
ssl.client.props
trust.p12
EDIT #2:
I have a new set of log messages after refining logging:
2016-09-02 10:45:37.581 DEBUG 8820 --- [P=678944:O=0:CT] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'context.listener.classes' in [servletConfigInitParams]
2016-09-02 10:45:37.597 DEBUG 8820 --- [P=678944:O=0:CT] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'context.listener.classes' in [servletContextInitParams]
2016-09-02 10:45:37.597 DEBUG 8820 --- [P=678944:O=0:CT] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'context.listener.classes' in [jndiProperties]
2016-09-02 10:45:37.597 DEBUG 8820 --- [P=678944:O=0:CT] org.springframework.jndi.JndiTemplate : Looking up JNDI object with name [java:comp/env/context.listener.classes]
2016-09-02 10:45:37.598 ERROR 8820 --- [P=678944:O=0:CT] c.i.w.naming.java.javaURLContextFactory : javaAccessorNotSet
2016-09-02 10:45:37.598 DEBUG 8820 --- [P=678944:O=0:CT] o.s.jndi.JndiLocatorDelegate : Converted JNDI name [java:comp/env/context.listener.classes] not found - trying original name [context.listener.classes]. javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
2016-09-02 10:45:37.599 DEBUG 8820 --- [P=678944:O=0:CT] org.springframework.jndi.JndiTemplate : Looking up JNDI object with name [context.listener.classes]
2016-09-02 10:45:38.623 DEBUG 8820 --- [P=678944:O=0:CT] o.s.jndi.JndiPropertySource : JNDI lookup for name [context.listener.classes] threw NamingException with message: Could not obtain an initial context due to a communication failure. Since no provider URL was specified, the default provider URL of "corbaloc:iiop:1.0#<MY_COMPUTERS_ADDRESS>:2809/NameService" was used. Make sure that any bootstrap address information in the URL is correct and that the target name server is running. Possible causes other than an incorrect bootstrap address or unavailable name server include the network environment and workstation network configuration.. Returning null.
2016-09-02 10:45:38.623 DEBUG 8820 --- [P=678944:O=0:CT] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'context.listener.classes' in [systemProperties]
2016-09-02 10:45:38.623 DEBUG 8820 --- [P=678944:O=0:CT] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'context.listener.classes' in [systemEnvironment]
2016-09-02 10:45:38.624 DEBUG 8820 --- [P=678944:O=0:CT] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'context.listener.classes' in [random]
2016-09-02 10:45:38.624 DEBUG 8820 --- [P=678944:O=0:CT] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'context.listener.classes' in [applicationConfigurationProperties]
2016-09-02 10:45:38.624 DEBUG 8820 --- [P=678944:O=0:CT] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'context.listener.classes' in any property source. Returning [null]
2016-09-02 10:45:38.625 DEBUG 8820 --- [P=678944:O=0:CT] org.springframework.jndi.JndiTemplate : Looking up JNDI object with name [java:comp/env/spring.mandatoryFileEncoding]
2016-09-02 10:45:38.627 ERROR 8820 --- [P=678944:O=0:CT] c.i.w.naming.java.javaURLContextFactory : javaAccessorNotSet
2016-09-02 10:45:38.627 DEBUG 8820 --- [P=678944:O=0:CT] o.s.jndi.JndiLocatorDelegate : Converted JNDI name [java:comp/env/spring.mandatoryFileEncoding] not found - trying original name [spring.mandatoryFileEncoding]. javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
2016-09-02 10:45:38.627 DEBUG 8820 --- [P=678944:O=0:CT] org.springframework.jndi.JndiTemplate : Looking up JNDI object with name [spring.mandatoryFileEncoding]
2016-09-02 10:45:39.634 DEBUG 8820 --- [P=678944:O=0:CT] o.s.jndi.JndiPropertySource : JNDI lookup for name [spring.mandatoryFileEncoding] threw NamingException with message: Could not obtain an initial context due to a communication failure. Since no provider URL was specified, the default provider URL of "corbaloc:iiop:1.0#<MY_COMPUTERS_ADDRESS>:2809/NameService" was used. Make sure that any bootstrap address information in the URL is correct and that the target name server is running. Possible causes other than an incorrect bootstrap address or unavailable name server include the network environment and workstation network configuration.. Returning null.
2016-09-02 10:45:39.635 DEBUG 8820 --- [P=678944:O=0:CT] org.springframework.jndi.JndiTemplate : Looking up JNDI object with name [java:comp/env/spring.mandatory_file_encoding]
2016-09-02 10:45:39.636 ERROR 8820 --- [P=678944:O=0:CT] c.i.w.naming.java.javaURLContextFactory : javaAccessorNotSet
2016-09-02 10:45:39.636 DEBUG 8820 --- [P=678944:O=0:CT] o.s.jndi.JndiLocatorDelegate : Converted JNDI name [java:comp/env/spring.mandatory_file_encoding] not found - trying original name [spring.mandatory_file_encoding]. javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
2016-09-02 10:45:39.637 DEBUG 8820 --- [P=678944:O=0:CT] org.springframework.jndi.JndiTemplate : Looking up JNDI object with name [spring.mandatory_file_encoding]
2016-09-02 10:45:40.645 DEBUG 8820 --- [P=678944:O=0:CT] o.s.jndi.JndiPropertySource : JNDI lookup for name [spring.mandatory_file_encoding] threw NamingException with message: Could not obtain an initial context due to a communication failure. Since no provider URL was specified, the default provider URL of "corbaloc:iiop:1.0#<MY_COMPUTERS_ADDRESS>:2809/NameService" was used. Make sure that any bootstrap address information in the URL is correct and that the target name server is running. Possible causes other than an incorrect bootstrap address or unavailable name server include the network environment and workstation network configuration.. Returning null.
2016-09-02 10:45:40.646 DEBUG 8820 --- [P=678944:O=0:CT] org.springframework.jndi.JndiTemplate : Looking up JNDI object with name [java:comp/env/spring.mandatory-file-encoding]
2016-09-02 10:45:40.646 ERROR 8820 --- [P=678944:O=0:CT] c.i.w.naming.java.javaURLContextFactory : javaAccessorNotSet
As the NMSV0307E WebSphere error says, you cannot use the java: namespace outside of a managed environment (application server or application client). You need to find the actual binding name of the EJB, for example by looking for relevant CNTR0167I messages in the SystemOut.log of the WebSphere Application Server that contains the EJB, and then use that name for your lookup.
can you share your code
but here in a glance
if you will use the Embedded tomcat you have to use WSI and for EJB you should not use the Embedded tomcat and deploy it as a WAR in Websphere or Jboss or WebLogic because they support EJB Transport, for example connection with WSI
public static final String CE_URI_WSI = "http://localhost:9080/wsi/FNCEWS40MTOM";
public static final String CE_URI_EJB = "iiop://localhost:9080/FileNet/Engine";
public static final String stanzaWSI= "FileNetP8WSI";
public static final String STANZA_EJB = "FileNetP8";
public void connCPE_WSI() {
// Get the connection
conn = Factory.Connection.getConnection(CE_URI_WSI);
// Get the user context
uc = UserContext.get();
uc.pushSubject(UserContext.createSubject(conn, username, password, stanzaWSI));
try {
// Get the default domain
Domain domain = Factory.Domain.getInstance(conn, null);
// Get an object store
ObjectStore os = Factory.ObjectStore.fetchInstance(domain, osName, null);
System.out.println("Con OKAY WSI");
System.out.println(os.get_DisplayName());
} finally {
// Pop the subject off the UserContext stack
uc.popSubject();
}
}
for more info this is a great book
FileNet P8 API

Spring Boot Actuator DataSourceHealthIndicator not working for auto-configured DataSource

I'm using an auto-configured DataSource in Spring Boot 1.3.6 and I'm using Actuator's health endpoint. However, the health endpoint does not include any database component in the output.
My application.properties is as follows:
spring.datasource.url=jdbc:oracle:thin:#localhost:1521:local
spring.datasource.username=vagrant
spring.datasource.password=vagrant
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
endpoints.enabled=false
endpoints.health.enabled=true
The output from the /health endpoint is:
{"status":"UP","diskSpace":{"status":"UP","total":499863515136,"free":121851781120,"threshold":10485760}}
I enabled trace logging and it looks like Spring Boot is autoconfiguring the health indicators before the datasource. Here is an excerpt from the trace log (note the timestamps):
2016-07-22 10:07:20.976 TRACE 7628 --- [restartedMain] o.s.b.a.condition.OnClassCondition : Condition OnClassCondition on org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration$DataSourcesHealthIndicatorConfiguration matched due to #ConditionalOnClass classes found: org.springframework.jdbc.core.JdbcTemplate
2016-07-22 10:07:20.977 TRACE 7628 --- [restartedMain] .b.a.a.OnEnabledHealthIndicatorCondition : Condition OnEnabledHealthIndicatorCondition on org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration$DataSourcesHealthIndicatorConfiguration matched due to All default health indicators are enabled by default
2016-07-22 10:07:23.304 TRACE 7628 --- [restartedMain] o.s.b.a.condition.OnClassCondition : Condition OnClassCondition on org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration$DataSourcesHealthIndicatorConfiguration matched due to #ConditionalOnClass classes found: org.springframework.jdbc.core.JdbcTemplate
2016-07-22 10:07:23.305 TRACE 7628 --- [restartedMain] o.s.b.a.condition.OnBeanCondition : Condition OnBeanCondition on org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration$DataSourcesHealthIndicatorConfiguration did not match due to #ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) found no beans
2016-07-22 10:07:23.577 TRACE 7628 --- [restartedMain] o.s.b.a.condition.OnBeanCondition : Condition OnBeanCondition on org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration matched due to #ConditionalOnMissingBean (types: javax.sql.DataSource,javax.sql.XADataSource; SearchStrategy: all) found no beans
2016-07-22 10:07:23.578 DEBUG 7628 --- [restartedMain] a.ConfigurationClassBeanDefinitionReader : Registered bean definition for imported class 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration'
2016-07-22 10:07:23.578 DEBUG 7628 --- [restartedMain] a.ConfigurationClassBeanDefinitionReader : Registering bean definition for #Bean method org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource()
Am I doing something wrong, or is this a bug in Spring Boot? Is there a way to change the order so that the datasource is initialised first?
My problem was caused by running the app from Eclipse. I also had a TestApplication class in src/test/java which had an exclusion for DataSourceAutoConfiguration. I excluded the TestApplication class from the component scanning (via excludeFilter on #ComponentScan) and the health endpoint worked as expected (i.e. it included database information).

Spring batch admin integration in the existing app with Batch Jobs

I have a maven based spring web application where I also have several spring-batch jobs integrated. Now to monitor these jobs I want to add Spring Batch Admin to this app.
What I have done so far is this.
1. added this in web.xml inside contextConfigLocation
classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml,
classpath*:/org/springframework/batch/admin/web/resources/webapp-config.xml
Added batch-default.properties file with following content.
batch.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
batch.jdbc.url=jdbc:sqlserver://localhost:1433;SelectMethod=cursor;Database=TestMe
batch.jdbc.user=aa
batch.jdbc.password=aa
batch.database.incrementer.class=org.springframework.jdbc.support.incremente.SqlServerMaxValueIncrementer
batch.data.source.init=false
batch.business.schema.script=
batch.schema.script=
batch.drop.script=
batch.remote.base.url=
& the file with this name batch-SQLSERVER.properties
batch.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
batch.jdbc.url=jdbc:sqlserver://localhost:1433;SelectMethod=cursor;Database=TestMe
batch.jdbc.user=aa
batch.jdbc.password=aa
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.SqlServerMaxValueIncrementer
batch.data.source.init=false
batch.business.schema.script=
batch.schema.script=
batch.drop.script=
batch.remote.base.url=
My db tables for the jobs are already created.
I get the following error:
[TRACE] 2015-03-26 12:01:04.299 [localhost-startStop-1] PropertySourcesPropertyResolver - getProperty("ENVIRONMENT:hsql", String)
[DEBUG] 2015-03-26 12:01:04.299 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT:hsql' in [servletConfigInitParams]
[DEBUG] 2015-03-26 12:01:04.299 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT:hsql' in [servletContextInitParams]
[DEBUG] 2015-03-26 12:01:04.299 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT:hsql' in [jndiProperties]
[DEBUG] 2015-03-26 12:01:04.299 [localhost-startStop-1] JndiTemplate - Looking up JNDI object with name [ENVIRONMENT:hsql]
[DEBUG] 2015-03-26 12:01:04.302 [localhost-startStop-1] JndiPropertySource - JNDI lookup for name [ENVIRONMENT:hsql] threw NamingException with message: Name [ENVIRONMENT:hsql] is not bound in this Context. Unable to find [ENVIRONMENT:hsql].. Returning null.
[DEBUG] 2015-03-26 12:01:04.302 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT:hsql' in [systemProperties]
[DEBUG] 2015-03-26 12:01:04.302 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT:hsql' in [systemEnvironment]
[TRACE] 2015-03-26 12:01:04.303 [localhost-startStop-1] SystemEnvironmentPropertySource - PropertySource [systemEnvironment] does not contain 'ENVIRONMENT:hsql'
[TRACE] 2015-03-26 12:01:04.303 [localhost-startStop-1] SystemEnvironmentPropertySource - PropertySource [systemEnvironment] does not contain 'ENVIRONMENT:HSQL'
[DEBUG] 2015-03-26 12:01:04.303 [localhost-startStop-1] PropertySourcesPropertyResolver - Could not find key 'ENVIRONMENT:hsql' in any property source. Returning [null]
[TRACE] 2015-03-26 12:01:04.303 [localhost-startStop-1] PropertySourcesPropertyResolver - getProperty("ENVIRONMENT", String)
[DEBUG] 2015-03-26 12:01:04.303 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT' in [servletConfigInitParams]
[DEBUG] 2015-03-26 12:01:04.303 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT' in [servletContextInitParams]
[DEBUG] 2015-03-26 12:01:04.303 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT' in [jndiProperties]
[DEBUG] 2015-03-26 12:01:04.303 [localhost-startStop-1] JndiTemplate - Looking up JNDI object with name [java:comp/env/ENVIRONMENT]
[DEBUG] 2015-03-26 12:01:04.304 [localhost-startStop-1] JndiLocatorDelegate - Converted JNDI name [java:comp/env/ENVIRONMENT] not found - trying original name [ENVIRONMENT]. javax.naming.NameNotFoundException: Name [ENVIRONMENT] is not bound in this Context. Unable to find [ENVIRONMENT].
[DEBUG] 2015-03-26 12:01:04.304 [localhost-startStop-1] JndiTemplate - Looking up JNDI object with name [ENVIRONMENT]
[DEBUG] 2015-03-26 12:01:04.304 [localhost-startStop-1] JndiPropertySource - JNDI lookup for name [ENVIRONMENT] threw NamingException with message: Name [ENVIRONMENT] is not bound in this Context. Unable to find [ENVIRONMENT].. Returning null.
[DEBUG] 2015-03-26 12:01:04.304 [localhost-startStop-1] PropertySourcesPropertyResolver - Searching for key 'ENVIRONMENT' in [systemProperties]
[DEBUG] 2015-03-26 12:01:04.304 [localhost-startStop-1] PropertySourcesPropertyResolver - Found key 'ENVIRONMENT' in [systemProperties] with type [String] and value 'SQLSERVER'
[TRACE] 2015-03-26 12:01:04.306 [localhost-startStop-1] PropertyPlaceholderHelper - Resolved placeholder 'ENVIRONMENT:hsql'
[TRACE] 2015-03-26 12:01:04.316 [localhost-startStop-1] TypeConverterDelegate - Converting String to [boolean] using property editor [org.springframework.beans.propertyeditors.CustomBooleanEditor#59bde227]
[TRACE] 2015-03-26 12:01:04.317 [localhost-startStop-1] TypeConverterDelegate - Converting String to [boolean] using property editor [org.springframework.beans.propertyeditors.CustomBooleanEditor#59bde227]
[TRACE] 2015-03-26 12:01:04.317 [localhost-startStop-1] TypeConverterDelegate - Converting String to [int] using property editor [org.springframework.beans.propertyeditors.CustomNumberEditor#414a9c78]
[DEBUG] 2015-03-26 12:01:04.318 [localhost-startStop-1] DefaultListableBeanFactory - Finished creating instance of bean 'placeholderProperties'
[INFO ] 2015-03-26 12:01:04.319 [localhost-startStop-1] PropertyPlaceholderConfigurer - Loading properties file from class path resource [org/springframework/batch/admin/bootstrap/batch.properties]
[INFO ] 2015-03-26 12:01:04.319 [localhost-startStop-1] PropertyPlaceholderConfigurer - Loading properties file from class path resource [batch-default.properties]
[INFO ] 2015-03-26 12:01:04.320 [localhost-startStop-1] PropertyPlaceholderConfigurer - Loading properties file from class path resource [batch-SQLSERVER.properties]
[ERROR] 2015-03-26 12:01:04.325 [localhost-startStop-1] ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'sessionFactory' defined in URL [file:/C:/tomcat-7.0.54/wtpwebapps/testme/WEB-INF/classes/applicationContext-dao.xml]: Could not resolve placeholder 'hibernate.dialect' in string value "
hibernate.dialect=${hibernate.dialect}
hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
hibernate.show_sql=${hibernate.show_sql}
hibernate.format.sql=${hibernate.format.sql}
hibernate.query.substitutions=${hibernate.query.substitutions}
"
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:220) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:84) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:669) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) ~[spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) [spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973) [catalina.jar:7.0.54]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467) [catalina.jar:7.0.54]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.54]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [catalina.jar:7.0.54]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [catalina.jar:7.0.54]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_71]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [?:1.7.0_71]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [?:1.7.0_71]
at java.lang.Thread.run(Thread.java:745) [?:1.7.0_71]
Mar 26, 2015 12:01:04 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'sessionFactory' defined in URL [file:/C:/tomcat-7.0.54/wtpwebapps/testme/WEB-INF/classes/applicationContext-dao.xml]: Could not resolve placeholder 'hibernate.dialect' in string value "
hibernate.dialect=${hibernate.dialect}
hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
hibernate.show_sql=${hibernate.show_sql}
hibernate.format.sql=${hibernate.format.sql}
hibernate.query.substitutions=${hibernate.query.substitutions}
"
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209)
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:220)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:84)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:669)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
About my requirements I need to be able to monitor jobs in my current application using the Spring batch admin.
Thank you for viewing it. I did follow the documentation on site. I also refer the code from spring in action book. I am using the version 1.3.0.RELEASE of spring batch with spring 3.2.0.RELEASE.
From the stacktrace itself I can say that the issue is with not reading the properties properly. But if I remove these file/configurations my application works just fine. I am passing -DEVIRONMENT="SQLSERVER" as runtime arguement. Please provide your inputs.
I have refered this question on SO : Integrating Spring Batch Admin in existing application.
I have answered similar issue in this question. When you integrate spring batch admin and spring batch application picks property resource loading configuration from spring batch admin. You need to override it to include locations where spring boot usually keeps config files.
Also I added comment there, we started with similar approach to have single spring boot application with spring batch jobs and spring batch admin for monitoring, this proved to be pain to integrate, we made it work but we had to configure all aspects much harder than if it was spring batch only app. You cannot use java configuration, only xml and much things are colliding (when you add #EnableScheduling annotation to use spring schedulers some of spring batch beans starts to be scheduled etc.)
We ended up with two apps, one which holds jobs and has spring batch only, and other application that has spring batch admin on top of same mysql DB which we use for monitoring only. You loose triggering of jobs through UI and rest from spring batch admin but we are triggering jobs through message queue so we needed only monitoring and that is good solution for us.

How to specify packagesToScan in HibernateJpaAutoConfiguration?

I'm using HibernateJpaAutoConfiguration directly in a Spring unit test. While Hibernate and EntityManager is configured, no entities are scanned.
Exception
10:29:36.377 [main] INFO o.s.b.f.a.AutowiredAnnotationBeanPostProcessor - JSR-330 javax.inject.Inject' annotation found and supported for autowiring
10:29:36.505 [main] TRACE o.s.b.b.PropertiesConfigurationFactory - Property Sources: org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$FlatPropertySources#65f8f5ae
10:29:36.638 [main] TRACE o.s.b.b.PropertiesConfigurationFactory - Property Sources: org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$FlatPropertySources#65f8f5ae
10:29:36.716 [main] TRACE o.s.b.b.PropertiesConfigurationFactory - Property Sources: org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$FlatPropertySources#65f8f5ae
10:29:36.818 [main] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'default'
10:29:36.842 [main] INFO o.h.jpa.internal.util.LogHelper - HHH000204: Processing PersistenceUnitInfo [
name: default
...]
10:29:36.979 [main] INFO org.hibernate.Version - HHH000412: Hibernate Core {4.3.6.Final}
10:29:36.980 [main] INFO org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
10:29:36.982 [main] INFO org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
10:29:37.234 [main] INFO o.h.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
10:29:37.599 [main] INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect
10:29:37.608 [main] INFO o.h.e.j.internal.LobCreatorBuilder - HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
10:29:37.648 [main] INFO o.h.h.i.a.ASTQueryTranslatorFactory - HHH000397: Using ASTQueryTranslatorFactory
10:29:37.742 [main] INFO o.h.tool.hbm2ddl.SchemaUpdate - HHH000228: Running hbm2ddl schema update
10:29:37.742 [main] INFO o.h.tool.hbm2ddl.SchemaUpdate - HHH000102: Fetching database metadata
10:29:37.744 [main] INFO o.h.tool.hbm2ddl.SchemaUpdate - HHH000396: Updating schema
10:29:37.745 [main] INFO o.h.tool.hbm2ddl.SchemaUpdate - HHH000232: Schema update complete
My workaround is to create my own LocalContainerEntityManagerFactoryBean as follows:
final LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setPersistenceUnitName("buzzPU"); // persistence.xml
factoryBean.setDataSource(dataSource);
factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
factoryBean.setPersistenceXmlLocation("classpath*:META-INF/donotparsepersistence.xml");
factoryBean.setPackagesToScan("org.soluvas.buzz.core.jpa");
Note that I don't use META-INF/persistence.xml
From the Spring Boot reference...
62.4 Separate #Entity definitions from Spring configuration
Spring Boot tries to guess the location of your #Entity definitions, based on the #EnableAutoConfiguration it finds. To get more control, you can use the #EntityScan annotation, e.g.
#Configuration
#EnableAutoConfiguration
#EntityScan(basePackageClasses=City.class)
public class Application {
//...
}
Using the following also helps:
#EntityScan("org.soluvas.buzz.core.jpa")
It is an alias for 'basePackages' property that configures a list of packages to scan for annotated entities.
This annotation provides an alternative to manually setting
LocalContainerEntityManagerFactoryBean.setPackagesToScan(String...)
and is particularly useful if you want to configure entity scanning in
a type-safe way, or if your LocalContainerEntityManagerFactoryBean is
auto-configured.

Resources