There are two spring-boot project like after:
service_one
service_two
they all can run success alone.
Now I had changed this way, I use service_all project to manage which services should run: such as jvm properties. The final project like after
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>
<groupId>com.demo.service</groupId>
<artifactId>service_all</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>service_all</name>
<dependencies>
<dependency>
<groupId>com.demo.service</groupId>
<artifactId>service_one</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.demo.service</groupId>
<artifactId>service_two</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.0.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
// Java class in service_all
#Slf4j
#SpringBootApplication
public class Application {
public static void main(String[] args) throws IOException {
/**
* Common
*/
ConfigurableApplicationContext commonContext =
new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run(args);
log.info(commonContext.getId() + " isActive: " + commonContext.isActive());
/**
* service_one
*/
if (commonContext.getEnvironment().containsProperty("service_one")) {
ConfigurableApplicationContext oneContext =
new SpringApplicationBuilder(ServiceOneApplication.class)
.parent(commonContext)
.sources(RefreshScope.class).run(args);
log.info(configContext.getId() + " isActive: " + oneContext.isActive());
}
/**
* service_two
*/
if (commonContext.getEnvironment().containsProperty("service_two")) {
ConfigurableApplicationContext twoContext =
new SpringApplicationBuilder(ServiceTwoApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
log.info(adminContext.getId() + " isActive: " + twoContext.isActive());
}
}
}
Now I can't package the service_one and service_two lib in service_all jar's lib.
So how can I resolve this?
PS:
I can't change service_one and service_two anything, only can use like a dependency;
I can't use maven parent;
Related
I want to generate a POM file using JAXB 3. I downloaded the XSD https://maven.apache.org/xsd/maven-4.0.0.xsd into src/main/xsd.
I generated the model classes using the JAXB maven plugin.
The POM file of the project is :
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.myproject</groupId>
<artifactId>test-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.evolvedbinary.maven.mojohaus</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>org.apache.maven.pom</packageName>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
</project>
The main class used to generate the sample POM is :
import org.apache.maven.pom.Dependency;
import org.apache.maven.pom.Model;
import org.apache.maven.pom.Model.Dependencies;
import org.glassfish.jaxb.core.v2.WellKnownNamespace;
import org.glassfish.jaxb.runtime.marshaller.NamespacePrefixMapper;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
public class Main {
public static void main(String[] args) throws JAXBException {
Model model = new Model();
model.setModelVersion("4.0.0");
model.setDependencies(new Dependencies());
Dependency dependency = new Dependency();
dependency.setGroupId("commons-io");
dependency.setArtifactId("commons-io");
dependency.setVersion("2.11.0");
model.getDependencies().getDependency().add(dependency);
JAXBElement<Model> elem = new JAXBElement<>(new QName("project"), Model.class, model);
JAXBContext context = JAXBContext.newInstance(Model.class);
Marshaller m = context.createMarshaller();
m.setProperty("org.glassfish.jaxb.namespacePrefixMapper", new NamespacePrefixMapper() {
#Override
public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
return switch (namespaceUri) {
case XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI -> "xsi";
case XMLConstants.W3C_XML_SCHEMA_NS_URI -> "xs";
case WellKnownNamespace.XML_MIME_URI -> "xmime";
default -> "";
};
}
});
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
m.marshal(elem, System.out);
}
}
My issue is, the output contains undesired ns2 prefixes. I didn't figure out how to tell the marshaller that the generated model uses the default namespace and not a namespace named ns2.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<project xmlns:ns2="http://maven.apache.org/POM/4.0.0">
<ns2:modelVersion>4.0.0</ns2:modelVersion>
<ns2:dependencies>
<ns2:dependency>
<ns2:groupId>commons-io</ns2:groupId>
<ns2:artifactId>commons-io</ns2:artifactId>
<ns2:version>2.11.0</ns2:version>
</ns2:dependency>
</ns2:dependencies>
</project>
I forgot to provide the namespace to the QName :
new QName("http://maven.apache.org/POM/4.0.0", "project")
And now the result looks good :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
</project>
There's no need for a prefix mapper, so the code can be simplified:
import org.apache.maven.pom.Dependency;
import org.apache.maven.pom.Model;
import org.apache.maven.pom.Model.Dependencies;
import javax.xml.namespace.QName;
import jakarta.xml.bind.JAXB;
import jakarta.xml.bind.JAXBElement;
public class Main {
public static void main(String[] args) {
Model model = new Model();
model.setModelVersion("4.0.0");
model.setDependencies(new Dependencies());
Dependency dependency = new Dependency();
dependency.setGroupId("commons-io");
dependency.setArtifactId("commons-io");
dependency.setVersion("2.11.0");
model.getDependencies().getDependency().add(dependency);
JAXBElement<Model> elem = new JAXBElement<>(new QName("http://maven.apache.org/POM/4.0.0", "project"), Model.class, model);
JAXB.marshal(elem, System.out);
}
}
I am using HelloFx project from gluon client samples. And used Java 11.0.10 withgluon client plugin 0.1.41 to build APK.
I've added default javafx TextField(javafx.scene.control.TextField) and PasswordField(javafx.scene.control.PasswordField).
When I run the app directly in desktop (linux), I was able to type inside the password field and the 'bullets' appear properly.
But when I built APK and tested in an android device, the bullets are not rendered correctly, they are shown as boxes.
So, I've created a new skin to change the 'mask character' of password field to \u2022 as shown in this stackoverflow answer. In desktop, it worked with no issues. In android device the characters are properly shown as bullets but when I tap on that field the keyboard either doesn't show up or hides if it is already showing up.
Here's the PasswordFieldSkin.java:
public class PasswordFieldSkin extends TextFieldSkin {
public static final char BULLET = '\u2022';
public PasswordFieldSkin(PasswordField passwordField) {
super(passwordField);
}
#Override
protected String maskText(String txt) {
TextField field = getSkinnable();
int n = field.getLength();
StringBuilder passwordBuilder = new StringBuilder(n);
for (int i = 0; i < n; i++) {
passwordBuilder.append(BULLET);
}
return passwordBuilder.toString();
}
}
Here's the pom.xml file:
<?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>
<groupId>hellofx</groupId>
<artifactId>hellofx</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>HelloFX</name>
<properties>
<main.class>hellofx.HelloFX</main.class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<javafx.version>15.0.1</javafx.version>
<javafx.maven.plugin.version>0.0.6</javafx.maven.plugin.version>
<client.maven.plugin.version>0.1.41</client.maven.plugin.version>
<charm.version>6.0.6</charm.version>
<glisten.afterburner.version>2.0.5</glisten.afterburner.version>
<attach.version>4.0.10</attach.version>
<connect.version>2.0.1</connect.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<!-- Added jackson dependency here -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.1</version>
</dependency>
<!-- Added JavaTime data type -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.12.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>${javafx.maven.plugin.version}</version>
<configuration>
<mainClass>${main.class}</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>com.gluonhq</groupId>
<artifactId>client-maven-plugin</artifactId>
<version>${client.maven.plugin.version}</version>
<configuration>
<target>${client.target}</target>
<mainClass>${main.class}</mainClass>
<reflectionList>
<list>hellofx.Person</list>
<list>com.fasterxml.jackson.core.JsonFactory</list>
</reflectionList>
<nativeImageArgs>
<nativeImageArg>--allow-incomplete-classpath</nativeImageArg>
</nativeImageArgs>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>desktop</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<client.target>host</client.target>
</properties>
</profile>
<profile>
<id>ios</id>
<properties>
<client.target>ios</client.target>
</properties>
</profile>
<profile>
<id>android</id>
<properties>
<client.target>android</client.target>
</properties>
</profile>
</profiles>
</project>
And finally, here's the main method:
public class HelloFX extends Application {
private Label parseStatusLabel = new Label("");
private String serializedString = null;
public void start(Stage stage) {
String javaVersion = System.getProperty("java.version");
String javafxVersion = System.getProperty("javafx.version");
Label label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
ImageView imageView = new ImageView(new Image(HelloFX.class.getResourceAsStream("/hellofx/openduke.png")));
imageView.setFitHeight(200);
imageView.setPreserveRatio(true);
TextField textField = new TextField();
textField.setText("Username");
PasswordField passwordField = new PasswordField();
passwordField.setSkin(new PasswordFieldSkin(passwordField));
passwordField.setText("Password");
VBox root = new VBox(30, imageView, label, textField, passwordField, parseStatusLabel);
root.setAlignment(Pos.CENTER);
Scene scene = new Scene(root, 640, 480);
scene.getStylesheets().add(HelloFX.class.getResource("styles.css").toExternalForm());
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
How to solve this issue?
Hi I am doing a small POC with AWS Lambda using Java,
I want to test a simple Lambda function call, which will accept a string
I am using Google's Gson to convert String to Json and use it in my demo program.
I referred this documentation for my demo -
http://docs.aws.amazon.com/lambda/latest/dg/get-started-step4-optional.html
and
http://docs.aws.amazon.com/lambda/latest/dg/java-create-jar-pkg-maven-and-eclipse.html
Here's my Project directory structure -
I am getting an error when I call the Lambda function with the following String -
"{'name':'Aniruddha','age':'25'}"
Here's the error -
{
"errorMessage": "com/google/gson/GsonBuilder",
"errorType": "java.lang.NoClassDefFoundError",
"stackTrace": [
"example.Hello.myHandler(Hello.java:11)",
"sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
"sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)",
"sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
"java.lang.reflect.Method.invoke(Method.java:498)"
]
}
Here's my Handler function -
package example;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class Hello {
public String myHandler(String request, Context context) {
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
QueryParams queryParams = gson.fromJson(request, QueryParams.class);
System.out.println("Name is: "+queryParams.getName()+" Age is: "+queryParams.getAge());
LambdaLogger logger = context.getLogger();
logger.log("received a Lambda request");
String message = "Hey there! " + queryParams.getName() + " you are " + queryParams.getAge() + " years old";
return message;
}
}
This is my PoJo -
package example;
public class QueryParams {
String name;
int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
This is the 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>doc-examples</groupId>
<artifactId>lambda-java-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lambda-java-example</name>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-core -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Alright as #JBNizet advised (check question's comments),
It solved the issue.
Here's the pom.xml we need -
<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>doc-examples</groupId>
<artifactId>lambda-java-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lambda-java-example</name>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-core -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I am new to spring and maven, i do have this app which is referring from, https://spring.io/guides/gs/rest-service/
I am using spring + maven.
I need to get the output into a simple html via tomcat, currently it is using embedded Apache Tomcat 7.
package hello;
public class Greeting {
private final long id;
private final String content;
public Greeting(long id, String content) {
this.id = id;
this.content = content;
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
}
package hello;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
#RequestMapping("/greeting")
public Greeting greeting(#RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
}
This is the main which uses spring boot, to run in embedded Apache.
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Can someone help me with this! What i need is simple web service without embedded tomcat. just need normal tomcat deploying.
pom.xml is as bellow.
<?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>
<groupId>org.springframework</groupId>
<artifactId>gs-rest-service</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
Perfect Solution and code to your Question
SpringBoot contains Embedded Tomcat, Hence there is no special configuration required in your POM.xml
Your POM.xml should like this below code. I have used bootsample as an artifact and hence rest are all same.
<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>com.yourcompany.app</groupId>
<artifactId>bootsample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<finalName>bootsample</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
</project>
Your Greeting Domain Object.
/**
*
*/
import org.springframework.stereotype.Component;
/**
* #author Praveen
*
*/
#Component
public class Greeting {
private final long id;
private final String content;
public Greeting(long id, String content) {
this.id = id;
this.content = content;
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
}
Your Controller, Before careful you have use #ResponseBody annotation, else you will get circularpath ViewResolver Exception, because SpringBoot sets default viewResolver. This #ResponseBody annotation will skip your ViewResolver problems.
/**
*
*/
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* #author Praveen
*
*/
#Controller
#EnableAutoConfiguration
#ResponseBody
//#ComponentScan
public class SimpleController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
#RequestMapping("/greeting")
public Greeting greeting(#RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SimpleController.class, args);
}
}
Please use the Maven Goals as indicated in below figure.
Your maven goals should be mvn clean package spring-boot:run -e
Once you execute this, your embedded tomcat will run and you can find your successful output.
Successful Log
Additionally you can refer this link Spring-boot reference documentation. for your WAR/JAR creation questions.
Add This to your POM
<packaging>war</packaging>
and do mvn install or mvn package
You will see in your target folder the artifact ending with xxx.war.original. That one can be deployed straight into Tomcat.
edit:- Update as per comments below. Following changes needs to be made as well.
#SpringBootApplication
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
Refer doc for more details as cited in the comments section.
I have setup an ldap server with Apache director studio:
This is my code:
import com.unboundid.asn1.ASN1OctetString;
import com.unboundid.ldap.sdk.*;
import com.unboundid.ldap.sdk.controls.SimplePagedResultsControl;
public class App {
/**
* #param args
* #throws LDAPException
*/
public static void main(String[] args) throws LDAPException {
LDAPConnection connection = new LDAPConnection("localhost", 10389, "uid=admin,ou=system","secret");//"cn=admin4directory,dc=ilex-si,dc=eu", "M3d2p5a4!");
//SearchRequest searchRequest = new SearchRequest("ou=people,dc=ilex-si,dc=eu", SearchScope.SUB,"(ixuid=*)");
SearchRequest searchRequest = new SearchRequest("ou=people,dc=example,dc=com", SearchScope.BASE,Filter.createEqualityFilter("objectClass", "person"));
ASN1OctetString cookie = null;
do
{
searchRequest.setControls(
new Control[] { new SimplePagedResultsControl(500, cookie) });
SearchResult searchResult = connection.search(searchRequest);
// Do something with the entries that are returned.
cookie = null;
for (Control c : searchResult.getResponseControls())
{
if (c instanceof SimplePagedResultsControl)
{
cookie = ((SimplePagedResultsControl) c).getCookie();
System.out.println("\ncookie = "+ cookie.toString());
}
}
} while ((cookie != null) && (cookie.getValueLength() > 0));
connection.close();
}
}
I want to do a paged query but with this code I have returned a blank cookie..
How can I print the cn = john smit and cn robert smith values??
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>it.abc</groupId>
<artifactId>LDAPPagedQueryExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>LDAPPagedQueryExample</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.mule.tools</groupId>
<artifactId>maven-mule-plugin</artifactId>
<version>1.6</version>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Thank you.
Have you tried the simple example at https://docs.ldap.com/ldap-sdk/docs/javadoc/com/unboundid/ldap/sdk/controls/SimplePagedResultsControl.html
For sure You SearchScope.BASE must be at LEAST SearchScope.ONE or better SearchScope.SUB.
Not sure what is implied "How can I print the cn = john smit and cn robert smith values??"