This week's book giveaway is in the Agile/Processes forum.
We're giving away four copies of Building Green Software: A Sustainable Approach to Software Development and Operations and have Anne Currie, Sarah Hsu , Sara Bergman on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Spring Boot Migration

 
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I would like to migrate a java application using Rest to Spring Boot. I am thinking in using Spring Boot Web starter for migrating an app written in Java.

Should I just "import" the code into the Spring Boot Rest app?

Regards, Isaac
 
author
Posts: 422
13
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm not sure how to answer. Migrating existing apps to Boot have a difficulty ranging from 1 (super easy) to 10 (insanely hard, don't even try it). It kinda depends on the app you're starting with. If you're starting with an existing (non-Boot) Spring application, it might be fairly straightforward. If you're starting with some other framework, then it might be more difficult.

At the risk of giving a trite answer: It depends.

Isaac Ferguson wrote:Hi all,

I would like to migrate a java application using Rest to Spring Boot. I am thinking in using Spring Boot Web starter for migrating an app written in Java.

Should I just "import" the code into the Spring Boot Rest app?

Regards, Isaac

 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am starting with the migration for it I am using the Spring Initializr to create the basic structure, but which one shoudl I use?

The project to migrate contains Rest Services and credentials. Which starter should I use ?

Regards, Isaac
 
Craig Walls
author
Posts: 422
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rest-Repositories is for automatically creating REST endpoints for any repositories you may have created with Spring Data. If you are using Doring Data, it’s certainly worth looking into.

For creating your own REST endpoints, not necessarily associated with a Spring Data repository, you should pick either Spring MVC (Web) or Spring WebFlux (Reactive Web). The choice here hinges on whether you are ready to go reactive in your app.


Isaac Ferguson wrote:I am starting with the migration for it I am using the Spring Initializr to create the basic structure, but which one shoudl I use?

The project to migrate contains Rest Services and credentials. Which starter should I use ?

Regards, Isaac

 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have choosen Spring MVC, Security and Jersey.

Jersey for REST, Security for authentication and Spring MVC?
 
Saloon Keeper
Posts: 28578
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to look at Spring REST: https://spring.io/guides/gs/rest-service/ as it seems to be illustrating something along what you're talking about.

In most cases, Spring modules are built on top of general modules, such as Spring JPA's ability to use Hibernate. And in fact, when you have a standard interface (such as JPA), often the underlying module is plug-replaceable.

So there's a very good chance that you could use Jersey and leverage it using Spring REST.

 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Spring JPA's ability to use Hibernate



The app I need to migrate it is only Rest and Authetication without persistence I understand that Spring Rest is usd when there is persistence.

 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You might want to look at Spring REST: https://spring.io/guides/gs/rest-service



This is Spring but I want to use Spring Boot and the right starter.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.springboottutorial.com/creating-rest-service-with-spring-boot
 
Tim Holloway
Saloon Keeper
Posts: 28578
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Isaac Ferguson wrote:

You might want to look at Spring REST: https://spring.io/guides/gs/rest-service



This is Spring but I want to use Spring Boot and the right starter.



Read it more carefully. There's Spring Boot sample code in there.

Also, I question that Spring REST requires persistence. Spring has a whole separate module realm for persistence and they don't tend to lump unrelated functions together.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Yes this is to make it executable...
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In fact for security I would like to use LDAP.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When starting the migration and I set up the basic Spring Boot structure I get the next error in the pom.xml.

Plugin execution not covered by lifeclicle configuration: org.apache.maven.plugins : maven-resources-plugin:3.1.0:(execution : default-testResources, phase:testResources.processs-test-resource)
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The pom.xml is this one:


 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am migrating a Java 2 EE app to Spring Boot and I ask myself which of the next Java EE2 could be correlated with Spring Boot. The same way that we can substitute @Inject by @Autowired.



The question is which ones have a Spring Boot counterpart.

 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically all is about using this dependency in the code.

 
Sheriff
Posts: 22839
132
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, I'd upgrade to the latest Spring Boot version, 2.1.1.RELEASE.

You can see the classes related to email sending in Spring (Boot) here:
* https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/mail/package-summary.html
* https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/mail/javamail/package-summary.html

In this case, JavaMailSender is the interface to inject. You can use MimeMessageHelper and MimeMessagePreparator to create the actual message. An example can be found on https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/mail/javamail/MimeMessageHelper.html. However, since MimeMessagePreparator is a functional interface, you can shorten that example:
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to use two @RestControllers in two dfferent classes and within each of them several @RequestMapping.

One of them follows the path /v1 it works and it is reflected in the tab Spring Elements.

The other class is in a different package within src/main/java but it is not automatically reflected in the tab Spring Element and is it not called when the app calls its path "v2"

Any strategy to make it works with v2?

 
Rob Spoor
Sheriff
Posts: 22839
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you give us the fully qualified names of these two classes, and the fully qualified name and annotations of the class annotated with @SpringBootApplication?

My guess is that the second class does not share a package structure with the @SpringBootApplication. If that's the case, you need to explicitly use @ComponentScan to include both sets of packages. @SpringBootApplication implies @ComponentScan without explicit packages / classes which is the same as @ComponentScan with the @SpringBootApplication class' package. If you use @ComponentScan you do not get this package for free anymore, that's why you need to add both sets.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Can you give us the fully qualified names of these two classes



@RestController
@RequestMapping("/v1")
/org.springframework.boot/src/main/java/ddddd/nton/rt/a/NtonController.java




@RestController
@RequestMapping("/v2")
/org.springframework.boot/src/main/java/ddddd/nton/v1/b/Nton.java





and the fully qualified name and annotations of the class annotated with @SpringBootApplication?





 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I pur quotes instead of "code"
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Where should be this data located in the original JEE app? I need to migrate it to the springmail.properties ->application.properties
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example when I comment @ComponentScan({ "ddddd.nton.v1.b"}) it works, but when not I get ERR_CONNECTION_REFUSED in the browser.

 
Rob Spoor
Sheriff
Posts: 22839
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just as I thought, the v1 controller shares a package structure with the @SpringBootApplication class. Both are in package ddddd.nton.rt.a, whereas the v2 controller lives in package ddddd.nton.v1.b (which is a odd, the versions don't match).

You have a few options:
1) Use @ComponentScan("ddddd.nton") to include everything under dddd.nton.
2) Use @ComponentScan({"dddd.nton.rt.a", "dddd.nton.v1.b"}) to include these exact two packages (and sub packages).
3) Like 2 put some combination of base packages (e.g. dddd.nton.rt and/or dddd.nton.v1).
4) Like 2 or 3 but using basePackageClasses (possibly with basePackages) with some classes instead of package names.

Isaac Ferguson wrote:Where should be this data located in the original JEE app? I need to migrate it to the springmail.properties ->application.properties


I think that depends on your container. In WebLogic those were defined in a mail session in the admin console. I can't remember how JBoss did it, and I've never really used GlassFish.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I add the @ComponentScan({"dddd.nton.rt.a", "dddd.nton.v1.b"}) I get



The same if I put the packages in different @ComponentScan
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added the next annotations





 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is an interface.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am migrating a JEE application to Spring Boot.Originally in JEE I had this code




After reading about Spring Boot loggers looks like it should be done like this:




Later in the code it is written;



Should the logs go into the console or to a particular file?
 
Rob Spoor
Sheriff
Posts: 22839
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on your logging configuration. I don't really know the defaults, but you can use a logback-spring.xml configuration file to change it. Alternatively, you can use the logging properties defined at https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html to configure them in your application.properties.
 
Rob Spoor
Sheriff
Posts: 22839
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Isaac Ferguson wrote: it is an interface.


Do you have an annotated implementation for this interface? For some interfaces Spring Boot can create implementations (e.g. CrudRepository), but definitely not all.
 
reply
    Bookmark Topic Watch Topic
  • New Topic