OrientDB with spring mvc configuration - spring

Please suggest me how can i configure the orientdb with spring mvc.
<bean id="databaseFactory" class="org.ops4j.orient.spring.tx.OrientObjectDatabaseFactory"
p:url="remote:localhost/MyDB" p:username="userName" p:password="pwd" />
<bean id="orTransactionManager" class="org.ops4j.orient.spring.tx.OrientTransactionManager"
p:databaseManager-ref="databaseFactory" />
I have added above code into my mvc-dispacher-servlet.xml file
and i have added dependencies also in to pom.xml
<dependency>
<groupId>org.ops4j.orient</groupId>
<artifactId>orient-spring-tx</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-core</artifactId>
<version>2.2.13</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-graphdb</artifactId>
<version>2.2.13</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-enterprise</artifactId>
<version>2.2.0-beta</version>
</dependency>
My OrientDb server is 2.2.13 version which is latest.
help me in configuring it.if possible suggest a sample project URL also.
Thank You

Related

Spring Boot for JPA support

I found only adding properties scanBasePackages on #SpringBootApplication can not enable feature of JPA on #Enity and JpaRepository. I have to add #EnableJpaRepositories and #EntityScan and basePackages properties on them. Is there any simpler solution on this? Thank you
Just go to the Spring Initializr site, specify your 'Group' and 'Artifact' (or live default ones), in the 'Dependencies' block choose "JPA" and "H2" (or another DB you need - see 'Switch to the full version' link), then click 'Generate Project'.
In the downloaded archive you can find the Spring Boot skeleton project with JPA support.
If you look into project pom.xml file you can see these dependencies:
<dependencies>
<!-- JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- H2 DB -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<!-- Other suff -->
</dependencies>
You will have to add those annotations to tell Spring container you want to enable the jpa features.
You will also have to add the following depenencies in your pom.xml to enable spring-data-jpa.
<!-- JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
Check out this GitHub project.

Spring Boot logging with Log4j2

Written simple POC to prove and test Spring Boot and log4j2 compatibility. Once successful I will move it to real application.
Please refer my POC source code:
https://github.com/Dennyss/SpringBootLog4j2POC
I know/read about Spring version and log4j2 compatibility from:
How to set up Spring Boot and log4j2 properly?
Found and tried recommendations described here:
Spring-Boot logging with log4j2?
But still not working. The problem is that both application logs and Spring logs are printing to console only.
Please refer maven dependencies below (from POC):
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
If I don't exclude Spring's logback and don't add boot-starter-log4j2 then application logs are printing to application file but Spring logs are not printing at all. I feel the problem somewhere with dependencies. Appreciate any help.
According to the Spring Boot Logging documentation, the location of the logging configuration file can be specified using the logging.config property. I noticed that your start.sh script is passing -Dlog4j.configurationFile. Normally, this would be sufficient for direct Log4J 2 integration, but Spring Boot uses logging.config.
After switching to this, it writes to the log files:
java -Dlogging.config=/share/LogPOC/log4j2.xml -cp poc.jar:libs/* com.poc.logger.Application

JSP not found when running Spring Boot in IDE, but works when running manually

I have a java web application code (checked out from remote git server - others users dont have my problem) and imported it into IntelliJ (newest edition), I performed from IDE following steps: maven clean install, run (its spring boot application so there are no arguments or parameters to configure in run configuration to set - I compared it with settings from IDE on ohter computer - no differences) and then I sent a request to server with resul "404 - /WEB-INF/../some.jsp not found) but in unzipped WAR this file exists ! Moreover, when I run this war manually (java -jar app.war) my request was sent successfully with positive result - view was displayed. So, there is definitelly sth wrong with IDE. I tried almost everything: i reinstalled IDE, I deleted .m2 repository, I checked out code again, I tried with different IDE version but problem still arrives. What may be wrong ?
maybe your application use dispatcher servlet ,so your request mapped and you cannot request to exact path of jsp file and your browser show 404 not found
,check your web.xml that has like this code
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
and search *.xml file that use jspResolver or somthing like this
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
if you find it, you should request for example like this
http://localhost:8080/nameofyourapp/index
instead of http://localhost:8080/nameofyourapp/WEB-INF/view/index.jsp
Spring Boot does not include Jasper by default and therefore JSP rendering doesn't work unless you explicitly include the library:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
The below libs are also necessary, hope you have already added:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper-el</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jsp-api</artifactId>
<version>${tomcat.version}</version>
</dependency>

how to use hawt.io with spring boot and an embedded Jetty

I have an Apache camel application which starts as an 'fat-jar' including an Jetty server.
Is it possible to add hawt.io to the jar in order to use hawt.io for this application?
I tried to add hawt.io with
<dependency>
<groupId>io.hawt</groupId>
<artifactId>hawtio-core</artifactId>
<version>1.4.47</version>
</dependency>
<dependency>
<groupId>io.hawt</groupId>
<artifactId>hawtio-plugin-mbean</artifactId>
<version>1.4.47</version>
</dependency>
<dependency>
<groupId>io.hawt</groupId>
<artifactId>hawtio-springboot</artifactId>
<version>1.4.47</version>
</dependency>
<dependency>
<groupId>io.hawt</groupId>
<artifactId>hawtio-web</artifactId>
<version>1.4.47</version>
<type>war</type>
</dependency>
but "/localhost:[my port]/hawtio" does not respond.
You would need to add some code to tell Jetty to add the hawtio-web WAR file as a context-path to jetty itself.
See how we do this from hawtio embedded
https://github.com/hawtio/hawtio/blob/master/hawtio-embedded/src/main/java/io/hawt/embedded/Main.java

Spring Data JPA Error for 1.7.0.M1 query lookup strategy Exception

I was trying to Integrate Spring Data JPA with custom queries added in my repository.The following error made me crazy
"You have defined query method in the repository
but you don't have no query lookupstrategy defined.
The infrastructure apparently does not support query methods!"
Can Anyone tell me how to solve this?
Upgrade the spring-data-commons dependency to 1.9.0.RELEASE.
<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.9.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
It was solved when downgraded to 1.6.2.RELEASE
<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<!-- <version>1.7.0.M1</version> -->
<version>1.6.2.RELEASE</version>
</dependency>

Resources