Category Archives: exception

javax.servlet.ServletException: Circular view path

Problem :

javax.servlet.ServletException: Circular view path [error]: would dispatch back to the current handler URL [/latestOrder] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)



Solution :

You’ve annotated the controller method as producing JSON or String or any other object . You probably want to annotate the method with @ResponseBody and change its return type to allow you to return an object representation of the JSON that you want to include in the response


Preview:
  @RequestMapping(value="latestOrders",method = RequestMethod.GET)
public @ResponseBody List<Order> listProducts(Model model) throws JMSException{
List<Order> list=new ArrayList();
list.add(staff1)
return list;
}

103 total views, no views today

Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;

Problem :

Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;

Solution :

getContextPath() was added with Servlet 2.5, does your version of Jetty supports that ? 


Might also want to check that you do not have some older or duplicate version of j2ee around.

Indicates that Jetty 6.1.x supports Servlet 2.5 , make sure you don’t have a pre-2.5 servlet version around. If this gets loaded before the 2.5 version, the entire classpath sees only Servlet 2.0 API (the 2.5 doesn’t even gets loaded).

so exclude it from the maven pom.xml

Exclusion entry
 <exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>

76 total views, 1 views today

Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: Unable to find main class

Solutions: 


Solution 1 :

You needed to change the packaging parameter to jar from pom. Also, the repositories, pluginRepositories, the maven-compiler-plugin and the spring-boot-maven-plugin’s version and executions weren’t needed.

Solution 2: 

Try mvn install and see if it works

Solution 3:


Preview:
<properties>
    <!-- The main class to start by executing java -jar -->
    <start-class>com.mycorp.starter.HelloWorldApplication</start-class>
</properties>
Solution 4:

Enable the main() method in your Application.java.

Configure spring-boot-maven-plugin to specify the class with the main class (Spring should find it anyway if you have one, but good to be explicit):


Preview:
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>${spring-boot-version}</version>
    <configuration>
        <mainClass>the.package.of.Application</mainClass>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

72 total views, no views today

Required request body content is missing: org.springframework.web.method.HandlerMethod


You can’t send a request body with an HTTP GET request. You should modify your call so that it only supports POST, and POST your JSON to that endpoint.

If you want to GET information about a bean, you should create a separate controller method that does that (and does not require a request body).

Also, double-check your endpoint definitions  in the $.ajax call.

74 total views, no views today

exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.json.JSONObject

Could not write content: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) )


controller methods return simple POJOs – Collection<Bookmark>, and Bookmark, etc., 

When an HTTP request comes in that specifies an Accept header, Spring MVC loops through the configured HttpMessageConverter until it finds one that can convert from the POJO domain model types into the content-type specified in the Accept header, if so configured.

Spring Boot automatically wires up an HttpMessageConverter that can convert generic Object’s to JSON, absent any more specific converter. HttpMessageConverter s work in both directions: incoming requests bodies are converted to Java objects, and Java objects are converted into HTTP response bodies.

To solve Exception just override the default behaivour of the HttpMessageConverter provided by spring.




    @Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
jsonConverter.setObjectMapper(objectMapper);
return jsonConverter;
}


This will do the trick for you.

76 total views, no views today

Exception at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass)

You might end up with this exception while doing your one to one ,or many to one relationship in hibernate.

Exception:
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:135)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1127)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1283)
at com.javatpoint.Test.main(Test.java:13)

To fix correct this exception Check following :

1. Your one to one mapping bean is pointing to correct column.
2. You have configured both table correctly.

Once you have correct these your exception will go away.

75 total views, no views today