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
Related
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 have combined the following two projects:
https://github.com/jpenninkhof/odata-boilerplate
and
https://github.com/isopropylcyanide/Jwt-Spring-Security-JPA
I have them working separatedly but when I combine them in the same project the call to http://localhost:9004/odata.svc doesn't work. The attribute attribute applicationContext is null. Actually in the tab Expresions is null but on the tooltip has still the right value
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.accolite.pru.health</groupId>
<artifactId>AuthApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>AuthApp</name>
<description>Demo project for Spring Boot</description>
<url>https://github.com/isopropylcyanide/Jwt-Spring-Security-JPA</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<developers>
<developer>
<name>Aman Garg</name>
<email>amangargcse#outlook.com</email>
<timezone>5</timezone>
<id>isopropylcyanide</id>
</developer>
</developers>
<licenses>
<license>
<name>Apache 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<developerConnection>scm:git:git#github.com:isopropylcyanide/Jwt-Spring-Security-JPA.git
</developerConnection>
<connection>scm:git#github.com:isopropylcyanide/Jwt-Spring-Security-JPA.git</connection>
<url>https://github.com/isopropylcyanide/Jwt-Spring-Security-JPA/tree/master</url>
<tag>HEAD</tag>
</scm>
<issueManagement>
<system>GitHub Issues</system>
<url>https://github.com/isopropylcyanide/Jwt-Spring-Security-JPA/issues</url>
</issueManagement>
<properties>
<!--Build -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
<!--Build -->
<jjwt.version>0.9.1</jjwt.version>
<log4j.version>1.2.17</log4j.version>
<spring.boot.version>2.3.0.RELEASE</spring.boot.version>
<freemarker.version>2.3.28</freemarker.version>
<swagger.version>2.9.2</swagger.version>
<expiring.map.version>0.5.9</expiring.map.version>
<!--Sonar / Code Coverage -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPaths>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPaths>
<surefire.version>2.19.1</surefire.version>
<sonar.language>java</sonar.language>
<jacoco.version>0.8.2</jacoco.version>
<sonar.exclusions>**/*Configuration.java,**/*Exception.java,**/conf/**/*,**/model/**/*</sonar.exclusions>
<java.version>1.8</java.version>
<cxf.version>3.3.6</cxf.version>
<olingo.version>2.0.11</olingo.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.14.FINAL</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-odata2-jpa-processor-api</artifactId>
<version>${olingo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-odata2-jpa-processor-core</artifactId>
<version>${olingo.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</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.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!--Log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!--Jwt -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>${jjwt.version}</version>
</dependency>
<!-- For Java 8 Date/Time Support -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<!--Swagger UI -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<!--Swagger 2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<!--Expiring Map -->
<dependency>
<groupId>net.jodah</groupId>
<artifactId>expiringmap</artifactId>
<version>${expiring.map.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-odata2-jpa-processor-api</artifactId>
<version>${olingo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-odata2-jpa-processor-core</artifactId>
<version>${olingo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-odata2-api</artifactId>
<version>${olingo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-odata2-core</artifactId>
<version>${olingo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-odata2-api-annotation</artifactId>
<version>${olingo.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<!--Jacoco Code Coverage Plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<!-- pre-unit-test execution helps setting up some maven property, which
will be used later by JaCoCo -->
<execution>
<id>coverage-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${project.basedir}/target/jacoco.exec</destFile>
<!-- passing property which will contains settings for JaCoCo agent.
If not specified, then "argLine" would be used for "jar" packaging -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>download-sources</id>
<goals>
<goal>sources</goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
AuthAppApplication.java
package com.accolite.pru.health.AuthApp;
#SpringBootApplication
#EntityScan(basePackageClasses = {
AuthAppApplication.class,
Jsr310JpaConverters.class
})
public class AuthAppApplication {
public static void main(String[] args) {
SpringApplication.run(AuthAppApplication.class, args);
}
}
StringContextUtil.java
package com.accolite.pru.health.AuthApp.utils;
#Component
public class SpringContextsUtil implements ApplicationContextAware {
final Logger logger = LoggerFactory.getLogger(SpringContextsUtil.class);
private static ApplicationContext applicationContext;
public SpringContextsUtil() {
logger.debug("Loading SpringContextsUtil");
}
#Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
logger.debug("Inject ApplicationContext: {} into SpringContextsUtil", applicationContext);
SpringContextsUtil.applicationContext = applicationContext;
}
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
public static Object getBean(String name) throws BeansException {
return applicationContext.getBean(name);
}
#SuppressWarnings({ "unchecked", "rawtypes" })
public static Object getBean(String name, Class requiredType) throws BeansException {
return applicationContext.getBean(name, requiredType);
}
public static boolean containsBean(String name) {
return applicationContext.containsBean(name);
}
public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
return applicationContext.isSingleton(name);
}
#SuppressWarnings("rawtypes")
public static Class getType(String name) throws NoSuchBeanDefinitionException {
return applicationContext.getType(name);
}
public static String[] getAliases(String name) throws NoSuchBeanDefinitionException {
return applicationContext.getAliases(name);
}
}
CxfServletRegister.java
#Configuration
public class CxfServletRegister {
#Bean
public ServletRegistrationBean<CXFNonSpringJaxrsServlet> getODataServletRegistrationBean() {
ServletRegistrationBean<CXFNonSpringJaxrsServlet> odataServletRegistrationBean = new ServletRegistrationBean<CXFNonSpringJaxrsServlet>(new CXFNonSpringJaxrsServlet(), "/odata.svc/*");
Map<String, String> initParameters = new HashMap<String, String>();
initParameters.put("javax.ws.rs.Application", "org.apache.olingo.odata2.core.rest.app.ODataApplication");
initParameters.put("org.apache.olingo.odata2.service.factory", "com.accolite.pru.health.AuthApp.utils.JPAServiceFactory");
odataServletRegistrationBean.setInitParameters(initParameters);
return odataServletRegistrationBean;
}
}
The rest of the code is as in the original projects,
It seems the following dependency was interfering. I removed it and now it works
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
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.
I write 2 controllers--GoodController and UserController, after importing spring-aspects, my UserController url 404, but GoodController is normal, I can't find the reason and don't know how to resolve. All my pom.xml is bellow:
project parent pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</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-test</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>top.lovely6</groupId>
<artifactId>user</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.43</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<!--shiro-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
<!--shiro-web-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>1.4.0</version>
</dependency>
<!--shiro-spring-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.4.0</version>
</dependency>
<!--shiro缓存-->
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-ehcache -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-ehcache</artifactId>
<version>1.4.0 </version>
</dependency>
<!-- swagger生成接口API -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<!-- 接口API生成html文档 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<!-- StringUtils -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<scope>provided</scope>
</dependency>
<!-- log :slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!--json:fastjson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
</dependencies>
user module pom.xml:-- no dependency
good module pom.xml
<dependencies>
<dependency>
<groupId>top.lovely6</groupId>
<artifactId>user</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>top.lovely6</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
ApplicationStarter module pom.xml
<dependencies>
<dependency>
<groupId>top.lovely6</groupId>
<artifactId>good</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>top.lovely6</groupId>
<artifactId>user</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
common module pom.xml:-- no dependency
UserController.java
#RestController
#RequestMapping("/user")
#EnableSwagger2
public class UserController {
#Resource
private UserService userService;
#RequiresRoles("admin")
#RequiresPermissions("create")
#PostMapping("")
#ResponseBody
public User createUser(#RequestBody User user) {
user.setCreateTime(new Date());
userService.save(user);
System.out.print(user);
return user;
}
//...
}
and GoodController is almost same as UserController.
log aop config:
#Slf4j
#Aspect
#Component
public class SysLogAspect {
#Pointcut("#annotation(top.lovely6.annotation.SysLog)")
public void logPointCut() {
}
#Around("logPointCut()")
public Object around(ProceedingJoinPoint point) throws Throwable {
long beginTime = System.currentTimeMillis();
//执行方法
Object result = point.proceed();
//执行时长(毫秒)
Long time = System.currentTimeMillis() - beginTime;
log.info(time.toString());
return result;
}
//...
}
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>