I have configured the following beans in my application context:
<bean id="bindConnectionPool" parent="abstractConnectionPool"
p:connectionFactory-ref="bindConnectionFactory" />
<bean id="bindConnectionFactory"
class="org.ldaptive.DefaultConnectionFactory"
p:connectionConfig-ref="bindConnectionConfig" />
<bean id="bindConnectionConfig" parent="abstractConnectionConfig" />
<bean id="abstractConnectionConfig" abstract="true"
class="org.ldaptive.ConnectionConfig"
p:ldapUrl="ldaps://myldap.example.com:636"
p:connectTimeout="3000"
p:useStartTLS="true"
p:sslConfig-ref="sslConfig" />
<!-- EDIT/UPDATE: -->
<bean id="sslConfig" class="org.ldaptive.ssl.SslConfig">
<property name="credentialConfig">
<bean class="org.ldaptive.ssl.X509CredentialConfig"
p:trustCertificates="mycert" />
</property>
</bean>
When I deploy the WAR to Tomcat I get the following exception:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean
with name ‘bindConnectionPool’ defined in ServletContext resource
[/WEB-INF/deployerConfigContext.xml]: Invocation of init method failed; nested exception
is java.lang.IllegalArgumentException: path must start with either classpath: or file:
What do I need to change the LDAPS-based URL to? Neither file: nor classpath: make sense here...thoughts?
Or, is ldapUrl a red herring, and is there some other path defined on this bindConnectionPool bean that isn't configured right? Oh, and obviously, can't post the LDAP server's actual name for security reasons (myldap.example.com is a different value).
Related
I am trying to set the proxy to spring rest template bean based on the property, I tried below configuration,
<bean id="forwardProxy" class="java.net.Proxy">
<constructor-arg>
<util:constant static-field="java.net.Proxy.Type.HTTP"/>
</constructor-arg>
<constructor-arg>
<bean class="java.net.InetSocketAddress">
<constructor-arg value="${forward.proxy.host}"/>
<constructor-arg value="${forward.proxy.port}"/>
</bean>
</constructor-arg>
</bean>
<util:constant id="noProxy" static-field="java.net.Proxy.NO_PROXY" />
<bean id="myRestTemplate" class="org.springframework.web.client.RestTemplate">
<constructor-arg>
<bean class="org.springframework.http.client.SimpleClientHttpRequestFactory">
<property name="connectTimeout" value="5000"/>
<property name="readTimeout" value="5000"/>
<property name="proxy" ref="#{ ${aem.enableProxy}==true ? forwardProxy : noProxy }"/>
</bean>
</constructor-arg>
</bean>
but I am getting below error saying No bean named 'DIRECT' available
Caused by (repeated) ... : org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRestTemplate' defined in class path resource [environment/application.xml]:
Cannot create inner bean 'org.springframework.http.client.SimpleClientHttpRequestFactory#1177bca' of type [org.springframework.http.client.SimpleClientHttpRequestFactory] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.http.client.SimpleClientHttpRequestFactory#1177bca' defined in class path resource [environment/application.xml]:
Cannot resolve reference to bean '#{ false==true ? forwardProxy : noProxy }' while setting bean property 'proxy'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'DIRECT' available
Proxy.Type.DIRECT is a enum, not sure how to create a bean for that. Is it possible to achieve what I am doing without creating a factory beans option.
Using spring version: 4.3.8
In rest-servlet.xml the below configuration is made ..
<property name="defaultViews">
<list>
<!-- JSON View -->
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
</bean>
<!-- XML view -->
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean class="org.springframework.oxm.castor.CastorMarshaller">
</bean>
</constructor-arg>
</bean>
<!-- PDF view -->
<bean class="com.hmkcode.view.PDFView">
</bean>
<!-- XLSX "Excel" view -->
<bean class="com.hmkcode.view.ExcelView">
</bean>
</list>
</property>
The below error occurs.. can any one provide solution for this.
Thanks in advance
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.web.servlet.view.ContentNegotiatingViewResolver#0'
defined in ServletContext resource [/WEB-INF/rest-servlet.xml]: Cannot
create inner bean
'org.springframework.web.servlet.view.xml.MarshallingView#1e9ad27' of
type [org.springframework.web.servlet.view.xml.MarshallingView] while
setting bean property 'defaultViews' with key [1]; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.web.servlet.view.xml.MarshallingView#1e9ad27'
defined in ServletContext resource [/WEB-INF/rest-servlet.xml]: Cannot
create inner bean
'org.springframework.oxm.castor.CastorMarshaller#10651e1' of type
[org.springframework.oxm.castor.CastorMarshaller] while setting
constructor argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.oxm.castor.CastorMarshaller#10651e1' defined in
ServletContext resource [/WEB-INF/rest-servlet.xml]: Invocation of
init method failed; nested exception is
java.lang.NoClassDefFoundError:
org/castor/core/util/AbstractProperties at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:290)
Looks like you miss the castor-core.jar in your classpath. Please add it.
if you use maven you can add
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-core</artifactId>
<version>1.3.3</version>
</dependency>
to your pom.xml rebuild your project and deploy it again.
Can anyone provide me the details as how to implement the "JobNameToJobRestartRequestAdapter" Class API for restarting the failed job by providing the name of the job that needs to be executed.
I created the context-xml file
<int:channel id="job-launches" />
<int:channel id="job-restarts" />
<int:service-activator id="restartJobClassProperties" input-channel="job-restarts" output-channel="job-requests">
<bean class="org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter">
<property name="jobLocator" ref="jobRegistry" />
<property name="jobExplorer" ref="jobExplorer" />
</bean>
</int:service-activator>
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.JobLocator">
<property name="name" value="JobNameGoesHere" />
</bean>
<bean id="jobExplorer" class="org.springframework.batch.core.explore.JobExplorer" />
While executing the main class which is reading this context.xml file I am getting below error:
Error creating bean with name
'org.springframework.integration.config.ServiceActivatorFactoryBean#0':
Cannot create inner bean
'org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter#0'
of type
[org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter]
while setting bean property 'targetObject'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter#0'
defined in class path resource
[META-INF/spring/restart-job-context.xml]: Cannot resolve reference to
bean 'jobRegistry' while setting bean property 'jobLocator'; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'jobRegistry' defined in class path
resource [META-INF/spring/restart-job-context.xml]: Instantiation of
bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Could not
instantiate bean class
[org.springframework.batch.core.configuration.JobLocator]: Specified
class is an interface
I want to implement the functionality for defining the batch job name which I would like to restart and the properties can be extracted from the jobexplorer based on the last executed step.
JobLocator is an interface. You can't define a bean that is just an interface. I think you want to use a JobRegistry. Below is what Spring Batch Admin uses:
<bean id="jobLoader" class="org.springframework.batch.core.configuration.support.AutomaticJobRegistrar">
<property name="applicationContextFactories">
<bean class="org.springframework.batch.core.configuration.support.ClasspathXmlApplicationContextsFactoryBean">
<property name="resources" value="classpath*:/META-INF/spring/batch/jobs/*.xml" />
</bean>
</property>
<property name="jobLoader">
<bean class="org.springframework.batch.core.configuration.support.DefaultJobLoader">
<property name="jobRegistry" ref="jobRegistry" />
</bean>
</property>
</bean>
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
The jobRegistry bean is a registry for the jobs to be looked up from (it does implement JobLocator. The jobLoader registers job definitions with the registry.
I am trying to read in a configuration file based on a system environment variable. My environment variable is FOO_ENV with value dev and dev.properties contains the properties bar.host and bar.port.
<context:property-placeholder />
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:${FOO_ENV}.properties"></property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
<bean id="myServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
<constructor-arg type="String" value="http://${my.host}:${my.port}/" />
</bean>
When I deploy this in tomcat, I get the following error:
11:48:39.324 [localhost-startStop-14] ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'myServer' defined in ServletContext resource [/WEB-INF/my-context.xml]:
Could not resolve placeholder 'my.host' in string value [http://${my.host}:${my.port}]
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
By replacing $FOO_ENV with dev in the context file, I have determined that the properties file can be read correctly. By changing FOO_ENV to other names, I can show that Spring is reading the environment variable.
It seems that the element
<property name="ignoreUnresolvablePlaceholders" value="true" />
should allow Spring to ignore that ${my.host} is not an environment variable, but though I've tried it in various places, I still get the same error, which indicates that my.host is not found.
You actually have two PropertyPlaceHolderConfigurers defined here. One via the context namespace and one explicitly. Spring is probably picking the one created via the context namespace. You could either set 'ignore-unresolvable' on the context tag and remove your propertyConfigurer bean like so:
<context:property-placeholder ignore-unresolvable="true"/>
Or if you need more control over PropertyPlaceHolderConfigurer go the other way and remove the context:property-placeholder tag.
I was trying to do some basic database operations. I'm using STS 3.2.0, Apache Tomcat 7.
My dispatcher-servlet.xml includes:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/mydb" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
Apache Tomcat fails miserably with thousands of exceptions, starting with this one :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource] for bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource] for bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
EDIT 1: I also downloaded 3.0.3.RELEASE version of the jar, and its still the same.
FINAL EDIT It seems, you should add your external jar files manually to your deployment directory as well (well if you don't use any extension that'd do that for you)
Try to add to POM.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
I think you should import selected jdbc jar into web app library.
if none of the above solution doesn't work, then manually add spring-jdbc jar file to webapp/WEB-INF/lib.