NetBeans: add Spring IOC to maven based Swing Application Framework project - java

I want to add spring IOC to maven based Swing Application Framework project. So I added to pom.xml dependencies:
<!-- Spring IOC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.0.RELEASE</version>
<scope>runtime</scope>
</dependency>
<!-- log4j for Spring -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<scope>runtime</scope>
</dependency>
And initializated ApplicationContext in main():
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.scan("com.mypackagewithbeans");
ctx.refresh();
launch(DesktopApplication1.class, args);
}
But I can't build project, because IDE can not see spring libraries at all. I tried to remove <scope>runtime</scope> line, but it does not fix the problem (IDE can not see annotations, for example, #Autowire).
What should I do to add the Spring IOC support to the NetBeans Swing Application Framework project (using maven)?

make sure that you've created a new Maven project in NetBeans and not just a 'Java Desktop Project' (these don't recognize the pom.xml). make sure to select the 'Swing Application Framework project' maven archetype when the wizard asks you to select an archetype.
to check, does your project icon have a small 'M' at the top left corner (indicating it's a maven project)

Related

Spring MVC Project error in Spring Tool Suite

In Spring Tool Suite 3.9.5, After Selecting New -> Project -> Spring Legacy Project -> Spring MVC Project. project is created but with errors. I even tried Maven -> Update Project but issues still exists.
Project Explorer
Problems
I have not installed Maven. I am using jdk 1.8
Seems as you are developing a Web project, most probably you are missing servlet.jar and other related web jars. So please proceed as follows:
Add following dependencies in your POM file with proper versions. Save the file.
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.1</version>
</dependency>
Do Maven -> Update Project (Install Maven in your system if not done)
Do a project clean build by going to Project -> Clean...
All error marks should go away by now. If not, go to Problem view by selecting Window -> Show View -> Problems
There check the issues in your project. Accordingly update the POM or change classpath. Now repeat steps 2 and 3.
EDIT :
It seems the following dependencies are missing for your project. Add these in your POM and follow the above steps.
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
Removed repository folder's files from m2 folder. STS is now making Spring MVC Project without any error.

Running Java application on Tomcat

I downloaded from github http://websystique.com/spring-boot/spring-boot-angularjs-spring-data-jpa-crud-app-example/ and import as maven and I cannot add this app to tomcat.
If i changed packaging from jar to war, I can add, but get 404 on localhost:8080/SpringBootCRUDApp
How can i run this app?
You do not need to add it to tomcat. Spring Boot uses a public static void main entry-point that launches an embedded web server for you. So just run main method.
In Your Application, you already added Springboot-starter-web Dependency in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
And packaged your application as "jar" as below in pom.xml
<packaging>jar</packaging>
"spring -boot-starter-web" dependency has inbuilt embedded Tomcat container, so you don't need to add anything in Tomcat container
You can run your application with below command in cmd
java -jar SpringBootCRUDApplicationExample.jar
<!-- marked the embedded servlet container as provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
use this example for your reference.

Using Eventuate framework

I have juste starting using evetn
I'm playing with some event sourcing things. This is the first time that I use that concept. After googling I found eventuate which is a java framework that helps you to implement that concept. I get started with that example:
https://github.com/eventuate-examples/eventuate-examples-java-spring-todo-list
I tested it and it looks very good. In that project there is many spring-boot project. Every microservice is a spring-boot project.
My question is How I can do in my IDE, eclipse, if I want to develop some services?
Best regards
Spring Boot projects are Maven build , so even you can add Maven dependencies and plugins/properties in the project for eventuate. Eventuate is a framework that has integration with Gradle and Maven project ( Visit http://eventuate.io/docs/javav2/maven-gradle-config.html ). For your refrence , I am adding some dependencies that might be help to you :
<dependencies>
<dependency>
<groupId>io.eventuate.client.java</groupId>
<artifactId>eventuate-client-java-spring</artifactId>
<version>${eventuateClientVersion}</version>
</dependency>
<dependency>
<groupId>io.eventuate.client.java</groupId>
<artifactId>eventuate-client-java-test-util</artifactId>
<version>${eventuateClientVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.eventuate.local.java</groupId>
<artifactId>eventuate-local-java-jdbc</artifactId>
<version>${eventuateLocalVersion}</version>
</dependency>
<dependency>
<groupId>io.eventuate.local.java</groupId>
<artifactId>eventuate-local-java-embedded-cdc-autoconfigure</artifactId>
<version>${eventuateLocalVersion}</version>
</dependency>
</dependencies>
Make sure to add this client library :
<properties>
<eventuateClientVersion>0.11.0.RELEASE</eventuateClientVersion>
<eventuateLocalVersion>0.5.0.RELEASE</eventuateLocalVersion>
</properties>

Spring-Hibernate 5 Support JAR files

I was trying to migrate Hibernate 3 to Hibernate 5.0.11 and I have downloaded and imported the Hibernate 5.0.11 core jar files. But when I try start my apache tomcat server on my IDE, it shows the error
org.springframework.beans.factory.BeanCreationException
org.springframework.beans.BeanInstantiationException:
This is because I am not able to download the Spring-Hibernate5 jar files.
Can anyone guide me to download and install those jar files.
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
Thanks in Advance.
I would not recommend you to download and manage your dependencies manually, since you can forget a required lib. Just let Maven (or other dependencies management tool) handle it for you:
<dependencies>
<!-- Other spring libs -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.11.Final</version>
</dependency>
</dependencies>
The class is located into spring-orm project, since its version 4.2.
However, it is already known that HibernateDaoSupport is not the best solution for your purposes anymore, take a look: Why is HibernateDaoSupport not recommended?

adding spring resources to eclipse

I'm struggling with adding spring framework libaries to my eclipse (with maven plug-in m2eclipse)
How can I achieve it in easiest way and why is it so complicated for a newbe user?
It's really frustrating that I can't move on with thing that simple like this.
Main goal is add spring libaries to my pom.xml file in depedencies tab in my dynamic web project in eclipse. Pom.xml is generated thanks to maven plug-in.
First of all I moved to the Eclipse Marketplace and installed Spring Tool Suite for Eclipse Kepler 4.3 and the result is nothing - still can't add libaries. Second attempt was installing the same suite for my whole windows, nothing worked so far.
Sample screenshot (all I can add is this):
Where is spring-web, spring-context, spring-webmvc etc. ? For me it's night and I don't have fresh eye on it but what am i missing here?
I have been using the Spring Framework and Java within Eclipse for a while now. And to be completely honest, the UI for pom.xml completely sucks. Just avoid the Eclipse UI for Maven and manipulate the raw XML. It is very intuitive and powerful.
So if you want to add a dependency, start using mvnrepository. From there you can get all the dependency snippets you need.
For 'spring-web' insert
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
In the <dependencies></dependencies> section. And you are set.
The same can be done for context and webmvc.
Just for convenience here is spring-webmvc:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
and here is spring-context
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>

Categories

Resources