Category Archives: Errors Solution

Error: Registry key ‘SoftwareJavaSoftJava Runtime Environment’CurrentVersion’

Problem :

Error: Registry key 'SoftwareJavaSoftJava Runtime Environment'CurrentVersion'

has value '1.8'
, but '1.7' is required.

Error: could not find java.dll

Error: Could not find Java SE Runtime Environment.




Solution :

open command prompt window

run this below command

Preview:

set PATH=c:Program FilesJavajdk1.6.0_45bin;%PATH%


change path according to your jdk location

88 total views, no 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

java.lang.object cannot be resolved / javax.cache.Cache cannot be resolved. It is indirectly referenced from required .class files

Problem Statements :
Description
Location
Type
The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
line 1
Java Problem
The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project
Unknown
Java Problem
The method myMethod(SomeClass) from the type MyOtherClass refers to the missing type (insert java type here: InputStream|File|Vector|IOException|etc)
line 123
Java Problem

Solutions : 

  • Close the project and reopen it.
  • Clean the project (It will rebuild the buildpath hence reconfiguring with the JDK libraries)
    OR
  • Delete and Re-import the project and if necessary do the above steps again.
The following steps could help:
  1. Right-click on project » Properties » Java Build Path
  2. Select Libraries tab
  3. Find the JRE System Library and remove it
  4. Click Add Library… button at right side » Add the JRE System Library (Workspace default JRE)

Add this  entry in your POM.xml file


Preview:


<dependency>

<groupId>javax.cache</groupId>

<artifactId>cache-api</artifactId>

</dependency>

76 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

Caused by: java.lang.IllegalArgumentException: ‘dataSource’ or ‘jdbcTemplate’ is required

A Simple DAO class extends JdbcDaoSupport, but, unable to inject or @autowired a “dataSource”, the method setDataSource is final, can’t override.

Solution

To quickly fix it, uses @PostConstruct to inject the dataSource like this :

@Repository
public class UserDetailsDaoImpl extends JdbcDaoSupport implements UserDetailsDao {

@Autowired
private DataSource dataSource;

@PostConstruct
private void initialize() {
setDataSource(dataSource);
}

}

Alternatively, create an own implementation of JdbcDaoSupport class, and do whatever you want. Dive inside the source code of JdbcDaoSupport, it’s just a simple helper class to create a jdbcTemplate.


Source :- https://www.mkyong.com/spring/how-to-autowire-datasource-in-jdbcdaosupport/

120 total views, no views today

org.hibernate.hql.internal.ast.querysyntaxexception: “table_name” is not mapped Spring boot

Put your SampleWebJspApplication.java in pl.test package and execute the application.

It is recommended by Spring Boot to run your application from the root package and all your entities, controllers,DAO’s and other service classes should be placed in child packages. This is not a hard and fast rule but it ensures all your subpackage annotated classes are scanned properly

In your case your User class is not scanned and Hibernate is not able to find the mapping for the same and eventually throwing the QuerySyntaxException when executing the from User query.

Currently Spring Boot will scan @Entity classes if they are placed in the same package or sub-packages where you specified the @SpringBootApplication annotation. Atleast, this is what I observed while developing spring boot apps lately.

If you do not want to move the location of the 

SampleApplication.java, then use 

@EntityScan(basePackages = "pl.test.model")


 annotation and this will fix the issue.

75 total views, no views today

spring boot controllers not initialized

Controllers are not initialize because you have not scan the packages for controller
add these lines in your main class.
If you are scanning a particular class for controller.
@SpringBootApplication
@ComponentScan(basePackageClasses = temInventoryController.class)
public class InventoryApp {
if you want to scan a whole package for controller add this.
@ComponentScan(basePackages = "com.home.controller")




65 total views, no views today

ORACLE : Io exception: The Network Adapter could not establish the connection

Not connecting to correct Database in oracle :



jdbc:oracle:thin:@<server_host>:1521:<instance_name>

the following commands will help:

1. Oracle query command to check the SID (or instance name):

select sys_context(‘userenv’,’instance_name’) from dual; 


2. Oracle query command to check database name (or server host):

select sys_context(‘userenv’, ‘server_host’) from dual;

66 total views, no views today

Maven – Pom.xml Issues.

Maven — > pom.xml error resolution



Problem 1. Could not calculate build plan: Plugin org.apache.maven.plugins:maven-jar-plugin:2.3.2 or one of its dependencies could not be resolved.

Soultion :- 
1 . Just go to the path 

C:Users<username>.m2repositoryorgapachemavenplugins 

2.  Delete the plugin which is causing the issue .
3. In Eclipse clean and build your project again
4. choose Maven->Update Dependencies.



Problem 2 : Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.5 from/to central (http://repo.maven.apache.org/maven2): The operation was cancelled.

Solution :- 
Rightclick on your project in eclipse and choose Maven->Update Dependencies
Choose Force update of snapshot release.


86 total views, no views today

java.lang.ClassCastException: org.hibernate.type.StringType cannot be cast to org.hibernate.type.VersionType

Problem:

Hibernate Tool While reverse engineering

Reason for this problem: In one of my table there was a field named version. Which Hibernate tool treated as field version and try to cast the same and it throws an exception because the type of the field was not what hibernate tool was expecting.

Solution: 

Open the hbm configuration file for corresponding table and change the configuration of that field from <version> to <property> .

86 total views, no views today