SolrJ Embedded Server Spring Config No longer working - spring

I have this spring config that I used in my tests:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:solr="http://www.springframework.org/schema/data/solr"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/solr
http://www.springframework.org/schema/data/solr/spring-solr-1.0.xsd">
<solr:embedded-solr-server id="tgySolrServer" solrHome="target/test-classes" />
</beans>
throwing now this exception
Caused by: java.lang.NoSuchMethodError: org.apache.solr.core.CoreContainer.<init>(Ljava/lang/String;Ljava/io/File;)V
at org.springframework.data.solr.server.support.EmbeddedSolrServerFactory.createPathConfiguredSolrServer(EmbeddedSolrServerFactory.java:101)
at org.springframework.data.solr.server.support.EmbeddedSolrServerFactory.initSolrServer(EmbeddedSolrServerFactory.java:77)
at org.springframework.data.solr.server.support.EmbeddedSolrServerFactoryBean.afterPropertiesSet(EmbeddedSolrServerFactoryBean.java:36)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
... 40 more
I currently have Solr 4.5.0 and spring-data-solr 1.0.0-RELEASE. What should I do to use the embedded server in my tests?

I got it working now
we need to add following dependency and repository to pom.xml
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>1.1.0.BUILD-SNAPSHOT</version>
</dependency>
<repositories>
<repository>
<id>spring-maven-snapshot</id>
<url>http://repo.springsource.org/libs-snapshot</url>
</repository>
</repositories>
That's it !!!

Related

Launch Spring web application using Spring Boot

I am trying to launch an existing web application using Spring Boot, without changing my existing application at all and keeping the spring-boot specific stuff in a separate module. I have the following maven structure:
parent
web-app
boot-app
I want to launch the web-app from the boot-app.
My boot module
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Web Application -->
<dependency>
<groupId>my.group.id.</groupId>
<artifactId>web-app</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>classes</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.2.5.RELEASE</version>
</plugin>
</plugins>
</build>
</project>
Application.java:
#EnableAutoConfiguration
#ImportResource("classpath:WEB-INF/myApp-servlet.xml")
public class Application extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
My web module
Structure:
src/main/
java/ --> Rest Endpoints etc.
webapp/ --> web resources, only important files shown
WEB-INF/
myApp-servlet.xml
web.xml
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>web-app</artifactId>
<packaging>war</packaging>
<name>some-name</name>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
</plugins>
</build>
</project>
web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>My Web App</display-name>
<!-- Servlet Configuration -->
<servlet>
<servlet-name>myApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myApp</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
myApp-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="some.corp.name.space"/>
<mvc:annotation-driven />
</beans>
My Problem
When I run Application.java I get the following error:
Caused by: java.io.FileNotFoundException: class path resource [WEB-INF/myApp-servlet.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
... 24 more
From what I can see, this is because the maven-war-plugin only includes classes in the jar it creates and does not include the webapp directory.
My Question
Is there any way for me to achieve this, with or without the maven-war-plugin?
The most important thing for me is to have the boot-app as a separate module.

JPA 2.0 + SPRING 3.1 + Weblogic 10.3.5

I need create a website in weblogic container, but i donĀ“t know how to connected jpa 2.0 to jndi weblogic connection and management with spring.
now i have one project but with errors, in this case my file setup are :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="unitPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/fact</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
</properties>
</persistence-unit>
</persistence>
and the error is:
weblogic.deployment.EnvironmentException: Error processing persistence unit unitPU of module web: Error instantiating the Persistence Provider class org.eclipse.persistence.jpa.PersistenceProvider of the PersistenceUnit factory-web-copyPU: java.lang.ClassNotFoundException: org.eclipse.persistence.jpa.PersistenceProvider
any sample or any idea to help me to solved this error o create a project jpa + spring + weblogic i will be greatful
You haven't got the class: org.eclipse.persistence.jpa.PersistenceProvider in your classpath. That is what is causing the exception. So add the .jar file containing this class into your classpath or if you are using Maven add this dependency:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>{artifact}</artifactId>
<version>{version}</version>
<scope>compile</scope>
</dependency>
And specify the appropriate artifactId.
See:
EclipseLink/Maven

Spring-Security OAuth2 setup - unable to locate oauth2 namespace handler

I'm trying to setup our REST server for OAuth2 with spring-security. (The server already supports spring-security without OAuth). Now I tried to follow the sparklr example and added the spring-security-oauth artifact to my maven (mvn dependency:tree shows it is available) as well as the namespace configuration to my spring-security-context.xml but all I get is:
Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security/oauth2]
Browsing to http://www.springframework.org/schema/security/ all I see are the .xsd files but no oauth2 folder.. How can that be? I am assuming the sparklr example is a working version, so what am I doing wrong?
Here's my spring-security-context header:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
If needed, here's the maven setup:
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth</artifactId>
<version>1.0.0.RC2</version>
</dependency>
You referer to OAuth2 but import the OAuth 1. replace the dependency to
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
You need to ensure that spring-security-oauth2 jar is present in classpath and it will work
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.4.0.RELEASE</version>
</dependency>

Spring dependency Error

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.7</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.0</version>
</dependency>
I got an error:
("cvc-complex-type.2.4.a: Invalid content was found starting with
element 'dependency'. One of
'{"http://www.springframework.org/schema/beans":import, "http://
www.springframework.org/schema/beans":alias,
"http://www.springframework.org/schema/beans":bean,
WC[##other:"http://www.springframework.org/schema/beans"]}' is
expected.)
i have been included (jackson-mapper-asl and jackson-core-asl) into my lib in my Work Space
not getting Why This Error Occurred Kindly Help.
You have two things mixed up: Spring Configuration files and Maven's project configuration file (pom.xml). The <dependency> element belongs in the pom.xml file, not in the Spring Configuration.
Also you do not need to include the jar files anywhere, Maven takes care of the dependencies.

Loading spring application context files that are inside a jar in classpath

I am trying to use ClassPathXmlApplicationContext in my java standalone code to load applicationContext.xml that is inside a jar file which is in my class path.
ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:**/applicationContext*.xml");
applicationContext.xml entry as follows,
<bean id="myAdder" class="com.foo.bar.MyAdder">
<property name="floatAdder" ref="floatAdder"/>
</bean>
And, when I try to load a bean that way I am getting NoSuchBeanException. Can't a bean by loaded in this way?
The jar file is added to my classpath as a maven dependency. When I see the Java Build Path in Eclipse for this project, I see this jar linked as M2_REPO/.../..
I was assuming I can load the bean inside the jar file as the jar is in classpath this way. Am I missing something?
Thanks,Abi
This should work, I just created the 2 projects and checked.
Project A (standard Maven project created with STS) has applicationContext.xml in src/main/resources.
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.D</groupId>
<artifactId>A</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="myAdder" class="com.foo.bar.MyAdder">
<property name="foo" value="bar" />
</bean>
</beans>
Project B:
pom.xml: same as A, except A is added as dependency:
<dependency>
<groupId>org.D</groupId>
<artifactId>A</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
Start.java in project B:
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"classpath*:**/applicationContext*.xml");
MyAdder myAdder = (MyAdder) context.getBean("myAdder");
System.out.println(myAdder.getFoo());
}
mvn install A first, then run Start in project B.
Do you really need the classpath*: prefix on that location? (Is that * legal?) I would have expected something more like:
ApplicationContext context = new ClassPathXmlApplicationContext("**/applicationContext*.xml);

Resources