Help please, I try to put Vaadin on my (Spring boot) server and after I set up a simple example, I get the following error:
The bean 'dispatcherServletRegistration', defined in class path resource [com/vaadin/flow/spring/SpringBootAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration.class] and overriding is disabled.
Then, to correct the error, I write in application.prop:
spring.main.allow-bean-definition-overriding=true
and get the following error:
Parameter 1 of constructor in org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration required a bean of type 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath' that could not be found.
POM.XML :
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.lopamoko
cloudliquid
0.0.1-SNAPSHOT
jar
<name>cloudliquid</name>
<description>Demo project for Spring Boot</description>
<pluginRepositories>
<pluginRepository>
<id>maven-annotation-plugin-repo</id>
<url>http://maven-annotation-plugin.googlecode.com/svn/trunk/mavenrepo</url>
</pluginRepository>
</pluginRepositories>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from com.lopamoko.cloudliquid.repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>ru.leon0399</groupId>
<artifactId>dadata</artifactId>
<version>0.8.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
<version>9.3.1</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-gson</artifactId>
<version>9.3.1</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-slf4j</artifactId>
<version>9.3.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</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-data-jpa</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
<version>1.7.16</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>0.7.4</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.6.0</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Its my Main application:
#SpringBootApplication()
#EntityScan("com/lopamoko/cloudliquid/dataModel")
#EnableJpaRepositories(basePackages = "com.lopamoko.cloudliquid.repository")
public class CloudliquidApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(CloudliquidApplication.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
FirebaseConfig firebaseConfig = new FirebaseConfig();
firebaseConfig.configurateFirebaseApplication();
}
#Bean
public DadataService dadataService() {
return new DadataServiceImpl();
}
#Bean
public DadataClient dadataClient() {
return Feign.builder()
.client(new OkHttpClient())
.encoder(new GsonEncoder())
.decoder(new GsonDecoder())
.logger(new Slf4jLogger(DadataClient.class))
.logLevel(Logger.Level.FULL)
.target(DadataClient.class, "https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/address");
}
#Bean
public CustomerDeliveryService customerDeliveryService() {
return new CustomerDeliveryServiceImpl();
}
#Bean
public OrderService orderService() {
return new OrderServiceImpl();
}
#Bean
public YandexService yandexService() {
return new YandexServiceImpl();
}
#Bean
public CategoryService categoryService() {
return new CategoryServiceImpl();
}
#Bean
public ShopService shopService() {
return new ShopServiceImpl();
}
#Bean
public CommentService commentService() {
return new CommentServiceImpl();
}
#Bean
public RatingService ratingService() {
return new RatingServiceImpl();
}
#Bean
public ProductService productService() {
return new ProductServiceImpl();
}
#Bean
public TomcatServletWebServerFactory tomcatFactory() {
return new TomcatServletWebServerFactory() {
#Override
protected void postProcessContext(Context context) {
((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
}
};
})
And Vaadin sample:
#Route("/TestMySelf")
public class MainView extends VerticalLayout {
public MainView() {
Label label = new Label("Hello its CloudLiquid");
}
}
What is the version of vaadin-spring-boot-starter you are using ?
From this , it said this is the known issues when certain old version of vaadin-spring-boot-starter is used with Spring Boot 2.1 and it will be fixed in some newer release :
We have another working workaround and are also close to finding the
proper fix without the need for the workaround. Regardless which
approach we use first, next week we should have platform releases that
work with Spring Boot 2.1. (v10, v11 and v12)
Sorry for keeping you on hold before being able updating to Spring
Boot 2.1, we should have looked at this earlier - my bad.
Then from the release note here, it said version 10.1.0 supports Spring Boot 2.1. So my advice is to upgrade the vaadin-spring-boot-starter to at least 10.1.0 or the latest version.
Related
I have been trying to implement Elastic Search 8.3 with spring boot.
i am getting the below exception:
Cannot convert value of type 'co.elastic.clients.elasticsearch.ElasticsearchClient' to required type 'org.springframework.data.elasticsearch.core.ElasticsearchOperations'
Below is my configuration for elastic search:
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
#Configuration
#EnableElasticsearchRepositories
public class ElasticConfig {
#Bean
public RestClient client() {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", "test321"));
HttpHost host = new HttpHost("localhost", 9200);
RestClient restClient = RestClient.builder(host)
.setHttpClientConfigCallback(new HttpClientConfigCallback() {
#Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
// TODO Auto-generated method stub
httpClientBuilder.disableAuthCaching();
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
}).build();
return restClient;
}
#Bean
public ElasticsearchClient elasticsearchTemplate() {
ElasticsearchTransport transport = new RestClientTransport(client(), new JacksonJsonpMapper());
return new ElasticsearchClient(transport);
}
}
Below is POM:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.2</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>aisha</groupId>
<artifactId>courseapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>courseapp</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<guava.version>20.0</guava.version>
<geoip2.version>2.15.0</geoip2.version>
<uap-java.version>1.4.0</uap-java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</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-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>${geoip2.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.github.ua-parser</groupId>
<artifactId>uap-java</artifactId>
<version>${uap-java.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.3.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.javafaker/javafaker -->
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Below is test class which call simple query for index product :
#SpringBootTest
public class ElkSpringTest {
#Autowired
private ElasticsearchRestTemplate elasticConfig;
#Test
void contextLoads() {
SearchResponse<ELKProduct> search;
try {
search = elasticConfig.search(s -> s.index("product").size(10), ELKProduct.class);
System.out.println(search.hits().total().value());
for (Hit<ELKProduct> hit : search.hits().hits()) {
System.out.println(hit.source().getId());
}
System.out.println("******ENding *****");
} catch (ElasticsearchException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Since elastic is upgraded to latest version 8.3. I am not able to set up elastic search in spring boot. I usually work with ElasticSearch repository to store the data in my indexs and query it using ElasticsearchOperations.
Current spring-data-elasticsearch(version 4.4) not much compatible with es version 8.3 (>7.17.6).
ES RestHighLevelClient can setApiCompatibilityMode(true) to enables compatibility mode that allows HLRC 7.17 to work with Elasticsearch 8.x. But the compatibility is not very good.
spring-data-elasticsearch(version 5.0) is now compatible with ES 8.5.0
It looks like the RestHighLevelClient is deprecated as of this version.
Check this documentation for implementing the client configuration.
I'm writing a small program for circuit breaker, When running the application it throws exceptions. springboot versin 2.5.4, Hystrix Version using 2.2.6
BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#659e0bfd]
Pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.ramgovindhare</groupId>
<artifactId>cricuitbreakerhystrix</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>CricuitBreakerHystrix</name>
<description>firstMicroserviceProject</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.8.RELEASE</version> <--- **See this**
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
CricuitBreakerHystrixApplication.java
#SpringBootApplication
#EnableCircuitBreaker
public class CricuitBreakerHystrixApplication {
public static void main(String[] args) {
SpringApplication.run(CricuitBreakerHystrixApplication.class, args);
}
}
Controller class
#RestController
public class CricutiBreakerHystrixController {
#GetMapping("/process")
#HystrixCommand(fallbackMethod = "doWork")
public String doProcess() {
String response = "This msg come for processes";
int i = 10 / 0;
return response;
}
public String doWork() {
return "This msg coming from doWork()...!!";
}
}
Just add spring-cloud-dependencies to dependencyManagement block:
<properties>
<spring.cloud-version>2020.0.3</spring.cloud-version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Corresponding version of spring-cloud can be find here
The spring boot version and spring cloud version should be matched in strict accordance with the official version. Link to the official website:spring-cloud
I am trying to implement REST microservices using Spring Boot in my project. I have created a controller for login page and also created repository.
But while hitting URL I am facing this issue o.s.web.servlet.PageNotFound: No mapping for GET /
Main Class
#ComponentScan(basePackages = {"com.springboot.controller.repository"})
#EntityScan(basePackages="com.springboot.controller.model")
#EnableJpaRepositories(basePackages="com.springboot.controller.repository")
#SpringBootApplication
public class CunsultustodayWebServicesApplication {
public static void main(String[] args) {
SpringApplication.run(CunsultustodayWebServicesApplication.class, args);
}
}
Controller
#RestController
#ComponentScan
#Controller
public class LoginController {
#Autowired(required=true)
private UserRepo userrepo;
#RequestMapping("/")
public String checkMVC()
{
return "Login";
}
#RequestMapping("/login")
public String loginHome(#RequestParam("email") String email, #RequestParam("password") String password, Model model)
{
User u = null;
try {
u= userrepo.findByEmail(email);
}
catch(Exception ex) {
System.out.println("User Not Found!!!");
}
if(u!=null) {
model.addAttribute("email", email);
return "HomePage";
}
return "Login";
}
}
Repository
#Service("UserRepo")
public interface UserRepo extends JpaRepository<User,Integer> {
User findByEmail(String email);
}
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.springboot.controller</groupId>
<artifactId>cunsultustoday-web-services</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cunsultustoday-web-services</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Please help me to find solution. Thank You
Your controller is probably not being picked up by the ComponentScan because you have limited to the package for the scan.
Try this:
// note #ComponentScan is removed as it is included already in #SpringBootApplication
#EnableJpaRepositories
#SpringBootApplication
public class CunsultustodayWebServicesApplication {
...
And This:
// note #Controller and #CompnentScan are removed
#RestController
public class LoginController {
I tried several ways to change the default jackson configuration within the spring boot and it doesn't work.
it simply ignores all configuration
#SpringBootApplication
public class AvaliacaoairtonApplication {
public static final String URL = "*";
public static void main(String[] args) {
SpringApplication.run(AvaliacaoairtonApplication.class, args);
}
#Bean
#Primary
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.build();
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
JavaTimeModule javaTimeModule = new JavaTimeModule();
javaTimeModule.addSerializer(LocalDate.class, new StdScalarSerializer<LocalDate>(LocalDate.class) {
#Override
public void serialize(LocalDate localDate, JsonGenerator jsonGenerator,
SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeString(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
}
});
objectMapper.registerModule(javaTimeModule);
return objectMapper;
}
}
application.properties
spring.jackson.serialization.write-dates-as-timestamps=false
POM
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>br.com.softplan</groupId>
<artifactId>avaliacaoairton</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>avaliacaoairton</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>6.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</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-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
result
enter image description here
I have a little problem with my Spring application.
I have configured different things with #Configuration-annotated classes and everything seems to work just fine when i run app in Netbeans. But now i want to build my application to executable jar-file, it doesnt work anymore. It seems like it dont find any annotated class.
Thanks for helping.
Main class:
#SpringBootApplication
#EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class StockServerApplication
{
public static void main(String[] args) throws IOException
{
// Check if settings exists
if(!AppSettings.settingsFileExists()){
AppSettings.writeExampleSettingsFile();
System.out.println("Settings-file not found. Example file has been written in the root-dir\nClosing...");
System.exit(0);
}
AppSettings.initialize();
if(!AppSettings.isValid()){
System.exit(0);
}
SpringApplication app = new SpringApplication(StockServerApplication.class);
Properties props = AppSettings.settingsToNativeProperties(AppSettings.applicationSettings);
props.put("spring.thymeleaf.mode", "LEGACYHTML5");
props.put("spring.thymeleaf.cache", "false");
props.put("spring.jpa.database", "default");
// Debug
// props.put("debug", "true");
app.setDefaultProperties(props);
app.run(args);
}
#Autowired
private AuthorizedUserRepository repo;
#PostConstruct
private void createAdmin(){
AuthorizedUser user = repo.getByUsername("Admin");
if(user == null){
// Generate admin-user
String possiblePasswordCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
String generatedPassword = RandomStringUtils.random(10, possiblePasswordCharacters);
user = new AuthorizedUser(null, null, "Admin", generatedPassword, null, AuthorizedUserRole.Admin);
repo.save(user);
System.out.println("\n\nCreated Admin-account with password: " + generatedPassword + "\n\n");
}
}
}
For example here are mine SecurityConfiguration class which dont be initialized at all.
#Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter
{
#Autowired
private AuthenticationFilter filter;
#Override
protected void configure(HttpSecurity http) throws Exception
{
Settings.ServerSettings set = AppSettings.applicationSettings.getServerSettings();
if(!set.isUseAuthentication())
return;
System.out.println("Initializing security-settings");
http.csrf().disable().authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/utils/**").permitAll()
.antMatchers("/app/**").permitAll()
.antMatchers("/authorize").permitAll()
.antMatchers(HttpMethod.POST, "/users/add/*").hasAuthority(AuthorizedUserRole.Admin.toString())
.antMatchers(HttpMethod.DELETE, "/users/delete/*").hasAuthority(AuthorizedUserRole.Admin.toString())
.antMatchers(HttpMethod.GET, "/users/all/*").hasAuthority(AuthorizedUserRole.Admin.toString())
.antMatchers(HttpMethod.PUT, "/users/changerole/*").hasAuthority(AuthorizedUserRole.Admin.toString())
.anyRequest().authenticated()
.and()
.addFilterBefore(filter, UsernamePasswordAuthenticationFilter.class)
.exceptionHandling()
.authenticationEntryPoint(new AuthEntryPoint());
}
#Bean
public FilterRegistrationBean authenticationFilterRegistrationBean(){
FilterRegistrationBean regBean = new FilterRegistrationBean();
regBean.setFilter(filter);
regBean.setOrder(1);
return regBean;
}
}
None of these classes works in jar-file. On IDE everything works just fine.
I have tried to search last couple days if someone has same problem but i didnt find anything.
pom.xml file.
I think this file contains alot of unnecessary dependecies. But i think that dont cause this problem.
<?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>maja</groupId>
<artifactId>StockServer</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>StockServer</name>
<description>Stock handling server</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>1.5.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.5.7.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.2.1.jre8</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.5.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<!-- JWT -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.6.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.156</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>